PDA

View Full Version : [SOLVED:] Code running extremely slow when creating PDFs



branston
12-03-2024, 01:09 PM
Hi

Not having any joy with this so really hoping someone else can help.

My code below loops through a list of candidates and creates a pdf file for each candidate (with a specific area from my excel sheet).

The problem I have is that creating the pdfs is VERY SLOW ! It almost takes 20 seconds to create one pdf. I'm sure there is a quicker way to do this ? I have 100s of candidates.

Can anyone help me here please to make more code more efficient or for it to run faster? TIA



Public Sub Print_all_candidates()
ActiveSheet.PageSetup.PrintArea = "A1:W49"
'CYCLE THROUGH ALL CANDIDATES
With Worksheets("Main")
For i = 1 To Range("StudentName").Rows.count
.Range("F1") = i
dC = "C:\Users\tom\documents\downloads\"
FILESAVENAME = dC & "\" & i & "candidate -" & ThisWorkbook.Worksheets("Main").Range("C2").Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FILESAVENAME _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next i
End With
Application.ScreenUpdating = True
MsgBox "All Files Created..."
End Sub

Paul_Hossler
12-03-2024, 03:55 PM
Hard to see without a small sample workbook with sample data for 3-4 names

branston
12-05-2024, 12:11 PM
Hi Paul

Eventually figured out what the problem is.

As each candidates pdf page is different, the code has to loop through each candidate value (F1), wait for that to load (as there's quite a bit of data) and then print to pdf I think.

I'm sure there was a time it loaded and printed faster but may be I had another script.

Thanks anyway for your help.

Paul_Hossler
12-05-2024, 04:24 PM
Glad you figured it out