Good Morning everybody!
I have an issue concerning my VBA Code. I actualy just want to create a loop that prints PDFs that are based on the same background template (which is in the sheet called AFFIDAVIT CREATOR) replacing some 4 boxes (labels and images) from the INPUT Sheet.
So far, the loop is working properly. Only problem: It generates the PDF files according to the given name (variable r) but refreshes the sheet AFTER exporting to PDF. Result: Mutliple files with different names but they all display the same :(
Any ideas?
That's my code:
Private Sub TryMe()
Dim r As Long
Dim strCap As String
Dim strCap2 As String
r = 4
Do Until Sheets("INPUT").Cells(r, 3).Value = ""
strCap = Sheets("INPUT").Cells(r, 3).Value
Sheets("AFFIDAVIT CREATOR").Label1.Caption = strCap
strCap2 = Sheets("INPUT").Cells(r, 5).Value
Sheets("AFFIDAVIT CREATOR").Label2.Caption = strCap2
If Sheets("INPUT").Cells(r, 4) = "OE" Then
Sheets("AFFIDAVIT CREATOR").Image1.Picture = LoadPicture(ActiveWorkbook.Path & "\OE_Logo.jpg")
Else
Sheets("AFFIDAVIT CREATOR").Image1.Picture = LoadPicture(ActiveWorkbook.Path & "\SF_Logo.jpg")
End If
If Sheets("INPUT").Cells(r, 6) = "OE" Then
Sheets("AFFIDAVIT CREATOR").Image2.Picture = LoadPicture(ActiveWorkbook.Path & "\OE_Logo.jpg")
Else
Sheets("AFFIDAVIT CREATOR").Image2.Picture = LoadPicture(ActiveWorkbook.Path & "\SF_Logo.jpg")
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, From:=1, To:=1, FileName:=ThisWorkbook.Path & "\" & Sheets("INPUT").Cells(r, 3) & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Sheets("AFFIDAVIT CREATOR").Calculate
r = r + 1
Loop
End Sub
Sheets("AFFIDAVIT CREATOR").Calculateand why it isn't before.ExportAsFixedFormat ...??If Sheets("AFFIDAVIT CREATOR").Calculate Then ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, From:=1, To:=1, FileName:=ThisWorkbook.Path & "\" & Sheets("INPUT").Cells(r, 3) & ".pdf" _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=False Else Sheets("AFFIDAVIT CREATOR").Calculate End IfStopbefore you.ExportAsFixedFormatto check if pictures are loaded after a few sec, if so run the sub further by pressing F5 in IDE. B) what if you move.ExportAsFixedFormatto separateSub onlyExport()and call it from current one in the same place likeCall onlyExport...