【发布时间】:2023-03-28 18:45:01
【问题描述】:
只是想问一下如何用vba导出PDF文件?问题是我确实有一张 10-F 和 10-B 表。下面的代码在 10-F 表中工作。我的问题是如何将 10-B 表中的数据与 10-F 一起导出?第一页是10-F的数据,10-B的数据在第二页。
10-B 工作表的范围是"B10:AD92"。
Sub Ver_PDF()
'Create and assign variables
Dim saveLocation As String
Dim rng As Range
lname = ThisWorkbook.Sheets("HOME").Range("K12")
fname = ThisWorkbook.Sheets("HOME").Range("K13")
Name = fname & " " & lname
pdfile = "V-" & Name & ".pdf"
saveLocation = ThisWorkbook.Path & "\V-PDF\" & pdfile
Set rng = Sheets("10-F").Range("B9:AD89")
Dim strFileExists As String
strFileExists = Dir(saveLocation)
If strFileExists <> "" Then
Dim Ret
'~~> Change this to the relevant file path and name
Ret = IsFileOpen(saveLocation)
If Ret = True Then
MsgBox "Please close the PDF file before proceeding...", vbCritical + vbOKOnly, "Error"
Exit Sub
End If
End If
rng.ExportAsFixedFormat Type:=xlTypePDF, _
FileName:=saveLocation, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
非常感谢任何帮助!谢谢!
【问题讨论】:
-
在打印之前,添加一个新的工作表,比如 10-print,将 10-B 和 10-F 范围复制并粘贴到 10-print,然后导出为 pdf 并删除 10-print。