【发布时间】:2021-03-26 10:14:00
【问题描述】:
我有一个需要保存为 PDF 的大型 Excel 文件。在每个工作簿中,我有 25 页需要保存为 pdf。
示例:工作簿 (x1) 有页 (25)。现在我需要为每个页面创建一个 PDF 文件。
为此,我在 VBA 中复制了一个代码,该代码为每个工作簿创建了一个 PDF 文件(不幸的是,不是为每个页面单独创建一个文件)。
VBA 代码:
Option Explicit
Sub ExportAsPDF()
Dim Folder_Path As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder path"
If .Show = -1 Then Folder_Path = .SelectedItems(1)
End With
If Folder_Path = "" Then Exit Sub
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
sh.ExportAsFixedFormat xlTypePDF, Folder_Path & Application.PathSeparator & sh.Name & ".pdf"
Next
MsgBox "Done"
End Sub
【问题讨论】: