如何解决如何自动生成多个 PDF 报告
我有一个 excel 文件,当我将名称复制/粘贴到单元格 A11 中时,工作表中的数据会通过名称上的 v-lookup 自动更新到另一个工作簿(这里没有问题)。目前,我必须手动将每个名称复制/粘贴到单元格 A11(然后工作表更新),然后将文件另存为 PDF,然后对每个名称重复该过程,以便为每个名称生成不同的 PDF 报告。我发现 VBA 代码可以自动制作/保存 PDF,但我需要增强它以自动将列表中的第一个名称复制/粘贴到 A11,然后生成 PDF,然后移动到列表中的下一个名称(复制/粘贴/generate PDF) 并重复直到列表的末尾。任何帮助表示赞赏!这是我拥有的当前代码的相关单元格:
粘贴单元格:A11
要复制的名称列表:B32:58
Sub PDFActiveSheet()
'www.contextures.com
'for Excel 2010 and later
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
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 = ActiveSheet
strTime = Format(Now(),"yyyymmdd\_hhmm")
'get active workbook folder,if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'replace spaces and periods in sheet name
strName = Replace(wsA.Name," ","")
strName = Replace(strName,".","_")
'create default name for savng file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'Update the Quarter/Year and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:="XXX" + Range("A11").Text,_
FileFilter:="PDF Files (*.pdf),*.pdf",_
Title:="Select Folder and FileName to save")
'export to PDF if a folder was selected
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
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。