Bigpotato 668
New Member
- Joined
- Apr 18, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
Hi all,
I use below code to loop all excel files in the directory and convert to pdf.
But the pdf output has page setup twisted.
How can I modify my coding to make my pdf output page setup as within one page?
Thank you all.
Public Sub Create_Invoice_PDFs()
Dim folderPath As String
Dim fileName As String
Dim invoiceSheet As Worksheet
folderPath = "C:\path\to\workbooks\" 'MODIFY THIS LINE - FOLDER CONTAINING THE WORKBOOKS
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
Application.ScreenUpdating = False
fileName = Dir(folderPath & "*.xls*")
Do While fileName <> ""
Workbooks.Open folderPath & fileName
Set invoiceSheet = Nothing
On Error Resume Next
Set invoiceSheet = ActiveWorkbook.Worksheets("RCTI")
Err.Clear
If Not invoiceSheet Is Nothing Then
invoiceSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:=folderPath & Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")) & "pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Else
Debug.Print fileName & " doesn't contain a 'RCTI' sheet"
End If
ActiveWorkbook.Close False
fileName = Dir
Loop
Application.ScreenUpdating = True
End Sub
I use below code to loop all excel files in the directory and convert to pdf.
But the pdf output has page setup twisted.
How can I modify my coding to make my pdf output page setup as within one page?
Thank you all.
Public Sub Create_Invoice_PDFs()
Dim folderPath As String
Dim fileName As String
Dim invoiceSheet As Worksheet
folderPath = "C:\path\to\workbooks\" 'MODIFY THIS LINE - FOLDER CONTAINING THE WORKBOOKS
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
Application.ScreenUpdating = False
fileName = Dir(folderPath & "*.xls*")
Do While fileName <> ""
Workbooks.Open folderPath & fileName
Set invoiceSheet = Nothing
On Error Resume Next
Set invoiceSheet = ActiveWorkbook.Worksheets("RCTI")
Err.Clear
If Not invoiceSheet Is Nothing Then
invoiceSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:=folderPath & Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")) & "pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Else
Debug.Print fileName & " doesn't contain a 'RCTI' sheet"
End If
ActiveWorkbook.Close False
fileName = Dir
Loop
Application.ScreenUpdating = True
End Sub