简体   繁体   English

无需选择即可将多个工作表导出为PDF

[英]Export Multiple Worksheets to PDF without Select

I have 4 sheets, say "Sheet1", "Sheet2", "Sheet3" and "Sheet4". 我有4张纸,分别是“ Sheet1”,“ Sheet2”,“ Sheet3”和“ Sheet4”。

For my PDF, I want to export the contents of Sheet3 and Sheet4, so it will be grouped into an Array as: 对于我的PDF,我想导出Sheet3和Sheet4的内容,因此将其分组为一个数组,如下所示:

Sheets(Array("Sheet3", "Sheet4"));

Now, normally to export to PDF, I would Select this, then have 现在,通常要导出为PDF,我将选择它,然后选择

ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:= _
"C:\filename.pdf", _
Quality:= xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

However, I want to have this Macro run totally in the background. 但是,我想让此Macro完全在后台运行。 If I was looking at Sheet1, and ran this macro, it will shift to Sheet3 because it is being selected which is disruptive to workflow. 如果我正在查看Sheet1,并运行了该宏,它将被切换到Sheet3,因为已选择它会对工作流程造成干扰。

I know how to do this for basic operations such as FillCell by declaring variables: 我知道如何通过声明变量来针对诸如FillCell之类的基本操作执行此操作:

Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet2")
' modify ws

since this works behind the scenes. 因为这在幕后起作用。

In summary, I would like to export multiple worksheets (not all) to PDF without the need to use Select, Activate, or similar which will change the view of the workbook/worksheet I am currently looking at. 总而言之,我想将多个工作表(并非全部)导出为PDF,而无需使用“选择”,“激活”或类似操作,这将改变我当前正在查看的工作簿/工作表的视图。

This should do the trick. 这应该可以解决问题。

Sheets("Sheet 1").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:= _
"C:\filename.pdf", _
Quality:= xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM