【发布时间】:2017-11-11 03:34:47
【问题描述】:
我希望将 2 个以上的 Excel 工作表保存为一个 PDF 文件。我有这个代码,但它只能保存单个文件,如何使它工作,以便它可以选择 2 个文件并将其保存为单个 PDF。
Sub CMSaveAsPDF()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = Worksheets("Design")
strPath = wbA.path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
strFile = "Design"
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
End sub
【问题讨论】:
-
如果手动,我们选择两张表,然后只保存为pdf,您的代码也可以这样做
-
感谢您的建议,我使用宏捕获代码并在数组中添加了工作表名称,它工作正常。Sheets(Array("Design", "Data")).Select