我目前有一个VBScript将整个Excel工作表导出为PDF。我想知道是否可以将脚本设置为仅导出所选区域。我知道这可以手动完成,但我已经完成了自动执行此过程的任务。如果实现,它将使整个报告过程更容易。我目前使用的VBScript是:
Sub PDFActiveSheet()
Dim ws As Worksheet
Dim strPath As String
Dim myFile As Variant
Dim strFile As String
On Error GoTo errHandler
Set ws = ActiveSheet
'enter name and select folder for file
' start in current workbook folder
strFile = Replace(Replace(ws.Name, " ", ""), ".", "_") _
& "_" _
& Format(Now(), "yyyymmdd\_hhmm") _
& ".pdf"
strFile = ThisWorkbook.Path & "\" & strFile
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
If myFile <> "False" Then
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "PDF version of report has been created."
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
我已经尝试更换&#34;设置ws = ActiveSheet&#34;到&#34;选择&#34;,这没有产生任何结果。另外,作为旁注,当选择发送到PDF时,它们会出现在单独的工作表上。是否可以将它们放在一张纸上?
提前感谢您提供给我的任何帮助。