I know it might seem to be a very simple question but I tried different methods to create a loop that would do what I'm looking for: Basically I have an excel sheet with 4 columns (unknown number of rows) in which I want to enter data. This data is then mirrored to a second sheet that contains the "printing design" that I use to create multiple PDF files. Problem is: I tried for 4 days now to create a loop and have not achieved anything!
If you could help me, this is the data entry: SCREENSHOT
Public Sub InputData()
Dim strCap As String
strCap = Sheets("INPUT").Cells(4, 3).Value
Label1.Caption = strCap
Dim strCap2 As String
strCap2 = Sheets("INPUT").Cells(4, 5).Value
Label2.Caption = strCap2
If Sheets("INPUT").Cells(4, 4) = "OE" Then
Image1.Picture = LoadPicture(ActiveWorkbook.Path & "\OE_Logo.jpg")
Else
Image1.Picture = LoadPicture(ActiveWorkbook.Path & "\SF_Logo.jpg")
End If
If Sheets("INPUT").Cells(4, 6) = "OE" Then
Image2.Picture = LoadPicture(ActiveWorkbook.Path & "\OE_Logo.jpg")
Else
Image2.Picture = LoadPicture(ActiveWorkbook.Path & "\SF_Logo.jpg")
End If
Application.Calculate
Call PrintPDF
End Sub
Sub PrintPDF()
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
'/// Change the output file name here! ///
sPDFName = "Affidavit" & " " & Sheets("INPUT").Cells(4, 3) & "_" & Sheets ("INPUT").Cells(4, 5) & ".pdf"
sPDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
Sheets("AFFIDAVIT CREATOR").PrintOut Copies:=1, From:=1, To:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
End Sub
I actually want to create One SINGLE PDF file for each row, so do this for row 4, 5, 6 etc. till VBA finds an empty row.
Any help would be highly appreciated, thanks in advance for all the help I was able to find on Stackoverflow and hopefully help to come!
Thanks,
Yannick