我正在编写一个 VBA 代码,以将 excel 中的一些工作表导出到相同的 PDF。我的 excel 文件中有几个图表表,每个表的名称都以“(name)_Chart”结尾。我想将所有名称以图表结尾的工作表导出到一个 PDF 文件。这是我正在尝试编写的代码。
Sub FindWS()
'look if it at least contains part of the name
Dim s As Worksheet
Dim strPath As String
strPath = ActiveWorkbook.Path & "\"
For Each s In ThisWorkbook.Sheets
If InStr(1, s.Name, Chart) Then
s.Activate
ActiveSheet.ExportAsFixedFormat xlTypePDF, strPath & s.Name & ".pdf"
Exit Sub
End If
Next s
End Sub
此代码不仅限于导出图表,而是导出整个工作簿。谁能帮我弄清楚我的代码中缺少什么。
谢谢!
修改后的代码:
Sub FindWS()
'look if it at least contains part of the name
Dim s As Worksheet
Dim strPath As String
strPath = ActiveWorkbook.Path & "\"
For Each s In ThisWorkbook.Worksheets
If InStr(1, s.Name, "Chart") = 0 Then
' Hide the sheet so it is not exported as PDF
s.Visible = False
End If
Next s
With ActiveWorkbook
.ExportAsFixedFormat xlTypePDF, strPath & "TEST.pdf"
End With
结束子