Forum Discussion
Continuous printing with Macros possible?
If you want to save all worksheets in the workbook in one continuous PDF, try this code instead:
Sub Macro2()
ChDir "C:\Users\<UserName>\Desktop"
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Name, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
Regards
yes... I would like all three sheets (that my current code saves) to be saved as one PDF, NOT the entire work book. Your code would save the entire workbook.... correct?
- Haytham AmairahSep 06, 2019Silver Contributor
Hi,
I figured out a good solution using this code:
Sub Macro5() 'Save specific sheets as PDF, but all in one file. ChDir "C:\Users\Haytham\OneDrive\Desktop" Sheets(Array("Workup 1", "PO List", "Sheet2")).Copy ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Name, Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False ActiveWorkbook.Close SaveChanges:=False End SubThis is the explanation of the commands in the code:
- Point Excel to the location where the file will be saved
- Create a new temporary workbook consists only from the sheets that you specify
- Create a one PDF from all sheets in that workbook and save it in the Desktop
- Close the temporary workbook without saving
Before you run the code, make sure that:
- Replace this path "C:\Users\Haytham\OneDrive\Desktop" with your specific path
- Identify the sheets that you want to include in the Array function
- The name of the sheet in the Array function should be in double quotes and each name is separated from the other by a comma
Hope that helps
- Budman36Sep 06, 2019Brass Contributor
Not sure what is going on. I cannot get a file path to work. I have tried a number of different ways. Here is my last attempt. Keep giving me a "Run-time error '76': Path not found"
- Haytham AmairahSep 06, 2019Silver Contributor
The error is expected because you didn't change this placeholder <UserName> in the path with the existing user name in your computer!
The best way to get the path of any file or folder is to press https://www.pcworld.com/article/251406/windows-tips-copy-a-file-path-show-or-hide-extensions.html simultaneously.
This will add a new option in the right-click menu called (Copy as path).
Also, you can replace the path line with the below which will save the PDF in the same path that the original workbook was saved in!
ChDir ThisWorkbook.Path
Sub Macro5() 'Save specific sheets as PDF, but all in one file. ChDir ThisWorkbook.Path Sheets(Array("Sheet1", "PO List")).Copy ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ ThisWorkbook.Name, Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False ActiveWorkbook.Close SaveChanges:=False End SubRegards
- Haytham AmairahSep 06, 2019Silver Contributor