宏以导出某些Excel工作表以分隔PDF
问题描述:
我有一个宏,可以将工作簿中的某些图纸导出以分隔PDF(用于报告目的).它在一个工作簿中对我来说正常工作,但是在另一个工作簿中,它正在导出所有工作表.我不知道我要去哪里.为了使事情变得更容易,我在要针对其用途进行自定义的地方用斜体表示.
I have a macro to export certain sheets in a workbook to separate PDF's (for reporting purposes). It works properly for me in one workbook, however, in a different workbook it is exporting ALL sheets. I can't figure out where I am going wrong. To make things easier, I italicized the spots where I would customize it for my purposes.
Sub ExportToPDFs()
' PDF Export Macro
' C:\ *location*
' Sheets(Array("*selected sheets*")).Select
Dim nm As String
Dim ws As Worksheet
For Each ws In Worksheets
ws.Select
nm = ws.Name
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\*location*" & "*Report Title*" & nm & Range("D8").Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Next ws
End Sub
答
您需要使用要导出的工作表名称填充数组sheets_to_select
.否则,这将为您工作.
You need to fill the array sheets_to_select
with the names of the sheets you want this to export. Otherwise, this will work for you.
Sub ExportToPDFs()
' PDF Export Macro
' C:\ *location*
' Sheets(Array("*selected sheets*")).Select
Dim nm As String
Dim ws As Worksheet
Dim i as Variant, sheets_to_select as Variant
sheets_to_select = Array("Sheet1","Sheet2","Sheet3")
For Each i in sheets_to_select
Thisworkbook.Sheets(i).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\*location*" & "*Report Title*" & i & Thisworkbook.Sheets("*The sheet you need the value of D8 from").Range("D8").Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Next i
End Sub