问题
Trying to save a set of sheets from a workbook to PDF format to the same folder and using workbook name.
After recording the macro with all the steps went back and tried to replace the pieces of the code by what I found in some of this forum's threads but now it is not working.
Current version is below. What did I break?
SaveToPDF Macro
Sheets(Array("AUDIT Info", "REVIEW", "FILES", "WARNINGS", "PURGE", "NonBIM", _
"Clashes", "ViewsManagement")).Select
Sheets("AUDIT Info").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & ActiveWorkbook.Name _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
Sheets("AUDIT Info").Select
回答1:
Try the code below:
Option Explicit
Sub SaveSheetsasPDF()
ThisWorkbook.Sheets(Array("AUDIT Info", "REVIEW", "FILES", "WARNINGS", "PURGE", "NonBIM", "Clashes", "ViewsManagement")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & ThisWorkbook.Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
回答2:
You will get an error if before running the macro one of the needed sheets will be selected/activated.. that's why you need to add the first line sheets(1).select
where the first sheet isn't in your array
来源:https://stackoverflow.com/questions/43345109/save-excel-as-pdf-in-current-folder-using-current-workbook-name