英文:
Exporting Excel ranges on different tabs as a pdf in VBA
问题
我尝试过以下方法,但它会将我在Sheet1中指定的范围应用于所有其他工作表。我还尝试过为每个工作表使用ActiveSheet.UsedRange.Select,但这会包括我不希望显示在PDF中的多余单元格。有没有人有任何想法?我在Windows上运行Office 365。
Sub SaveRangesAsPDF()
Sheets("Sheet1").Activate
ActiveSheet.Range("A1:L42").Select
Sheets("Sheet2").Activate
ActiveSheet.Range("A1:G35").Select
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Worksheets("Sheet3").Range("A2").Value, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
英文:
I've tried the below, but what it does it apply the range I specify in Sheet1 to ALL the other sheets. I've also tried using ActiveSheet.UsedRange.Select for each sheet, but that includes extraneous cells that I don't want displayed in the PDF. Does anyone have any ideas? I'm running Office 365 on Windows.
Sub SaveRangesAsPDF()
Sheets("Sheet1").Activate
ActiveSheet.Range("A1:L42").Select
Sheets("Sheet2").Activate
ActiveSheet.Range("A1:G35").Select
ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Worksheets("Sheet3").Range("A2").Value, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
Thanks so much!
答案1
得分: 2
以下是翻译好的部分:
没有选项可以在多个工作表上打印选择内容。您可以选择以下之一:
- 单个工作表上的选择。
- 活动工作表(或选择的工作表) - 考虑打印区域或不考虑打印区域。
- 整个工作簿 - 考虑打印区域或不考虑打印区域。
解决方案是在每个工作表上定义打印区域,然后打印所选的工作表。
英文:
There is no option to print selections on multiple sheets. You can choose one of:
- Selection on a single sheet.
- Active sheet(s) - an active sheet or selected sheets considering the printing area or not.
- Entire workbook - all sheets considering the printing area or not.
The solution for you is to define the printing area on each sheet and print selected sheets.
Sheet1.PageSetup.PrintArea = "$A$1:$L$42"
Sheet2.PageSetup.PrintArea = "$A$1:$G$35"
Sheets(Array("Sheet1", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Worksheets("Sheet3").Range("A2").Value, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论