Save excel as PDF in current folder using current workbook name

大城市里の小女人 提交于 2020-01-30 11:32:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!