excel - 如何使用vba excel打印为pdf多个word文档
问题描述
我有一个名称列表,我需要将它们中的每一个合并到预设的 Word 文档中,然后以 PDF 格式导出/打印/保存每个“证书”。
我在一段时间内放置了更改 Word 文档的代码,更改后我调用了我正在调用的函数“Imrpimir PDF”。这是整个代码:
While ThisWorkbook.Sheets("Lista de Presença").Cells(i, 2) <> Empty
If ThisWorkbook.Sheets("Lista de Presença").Cells(i, 4) = "Presente" Then
participante = UCase(ActiveWorkbook.Worksheets("Lista de Presença").Cells(i, 2))
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(ThisWorkbook.Path & "\" & ActiveWorkbook.Worksheets("Evento").Cells(1, 7).Text & " " & ActiveWorkbook.Worksheets("Evento").Cells(1, 2).Text & "\" & "Modelo.docx")
With wrdDoc
.Application.Selection.Find.Text = "#NOME"
.Application.Selection.Find.Execute
.Application.Selection.Range = participante
Imprime_PDF (participante)
Do
On Error Resume Next
Set wrdApp = GetObject(, "Word.Application")
If Not objWord Is Nothing Then
wrdApp.Quit False
Set wrdApp = Nothing
End If
Loop Until wrdApp Is Nothing
End With
Set wrdApp = Nothing
Set wrdDoc = Nothing
End If
i = i + 1
Wend
End Sub
函数“Imprime_PDF”是:
Function Imprime_PDF(participante)
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
ThisWorkbook.Path & "\" & ActiveWorkbook.Worksheets("Evento").Cells(1, 7).Text & " " & ActiveWorkbook.Worksheets("Evento").Cells(1, 2).Text & "\" & ActiveWorkbook.Worksheets("Evento").Cells(1, 2).Text & " - Certificado de " & participante & ".pdf ", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
IncludeDocProps:=True, _
CreateBookmarks:=wdExportCreateWordBookmarks, _
BitmapMissingFonts:=True
End Function
同时,此代码更改了所有 Word 文档,但仅将第一个文档另存为 pdf。
先感谢您!
解决方案
推荐阅读
- android - AysncTask vs ExecutorService?
- ios - 以编程方式添加时,rightAnchor 约束不适用 - swift
- python - 在具有多个外键 Django 的模型中创建记录
- python - 使用内置方法在python中将图像大小转换为二进制
- html - 如何始终保持我的父母为圆形?
- java - 适配器项目单击从片段
- kubernetes - 如何更新 StatefulSet 中的环境变量
- typo3 - TYPO3 PageLayoutView 从外部表中获取值
- python - 在 Jupyter 笔记本中的两个 df 显示之间添加空格
- python - subprocess.getstatusoutput('ls -l') 仅适用于 python shell?