Excel VBA 将选定的工作表导出为 PDF [英] Excel VBA to Export Selected Sheets to PDF
本文介绍了Excel VBA 将选定的工作表导出为 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码将选定的工作表从 Excel 2010 导出到单个 pdf 文件...
I'm using the following code to export selected sheets from Excel 2010 to a single pdf file...
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C: emp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
我的问题是它只导出第一张纸.有什么想法吗?
My problem is that it only exports the first sheet. Any ideas?
推荐答案
一旦你选择了一组工作表,你就可以使用选择
Once you have Selected a group of sheets, you can use Selection
考虑:
Sub luxation()
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:TestFolder emp.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
编辑#1:
进一步的测试表明,该技术取决于每个工作表上选择的单元格组.要获得全面的输出,请使用以下内容:
Further testing has reveled that this technique depends on the group of cells selected on each worksheet. To get a comprehensive output, use something like:
Sub Macro1()
Sheets("Sheet1").Activate
ActiveSheet.UsedRange.Select
Sheets("Sheet2").Activate
ActiveSheet.UsedRange.Select
Sheets("Sheet3").Activate
ActiveSheet.UsedRange.Select
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:UsersJamesDesktoppdfmaker.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
这篇关于Excel VBA 将选定的工作表导出为 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文