Forum Discussion
Tarek3
Oct 21, 2022Copper Contributor
Help with macro to export ONLY the first sheet of multiple excel workbooks to PDFs
Hi All! I have been working to clean up this macro code to allow it to run better on my computer. To preface, I have really little knowledge about all this, and have had a variety of people contribut...
HansVogelaar
Oct 21, 2022MVP
Perhaps it's a timing problem. Does it work if you add a couple of DoEvents lines in the loop?
'Loop until all found
Do Until fName = ""
Set wbSource = Workbooks.Open(fPath & fName)
DoEvents
'This is the part that may need to be changed
With wbSource
sFile = .Worksheets(1).Name & ".pdf"
.Worksheets(1).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
DoEvents
wbSource.Close SaveChanges:=False
'Get name of next file
fName = Dir()
Loop