如何解决需要在批量更新工具中调用其他Word宏
快速总结:我需要调用额外的宏来修改现有代码中的文档,这些代码将 Word 文件批量转换为 PDF(如果可能)。
长话:我有很久以前的代码(归功于我十年前找到的地方)。它使用文件对话框来允许选择多个文件,然后将这些选定的文件转换为 PDF。我有将近 1,800 个 Word 文档需要处理(使用代码 @timothyrylatt 在此处提供帮助:How to find table column,then move down and replace the cell's content IF it is "N/A"),然后再转换为 PDF。我尝试使用“调用”功能调用“演示”宏,并更改保存设置,但文件仅转换为 PDF,而不调用其他“演示”宏。我也尝试在不同的领域调用它,但没有成功。
注意:如果无法添加到现有代码中,是否还有办法至少选择多个文件,运行Demo宏,然后以类似方式保存并关闭?
预先感谢您的任何帮助!
Sub MassUpdate()
Dim wDoc As Word.Document
Dim FoundFile As Variant
Dim wDialog As FileDialog
Set wDialog = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
wDialog.AllowMultiSelect = True
If wDialog.Show <> -1 Then
Exit Sub
End If
For Each FoundFile In wDialog.SelectedItems
Set wDoc = Documents.Open(FoundFile,ReadOnly:=False,Visible:=False)
Call Demo
wDoc.ExportAsFixedFormat _
OutputFileName:=wDoc.Path & "\" & Left(wDoc.Name,InStrRev(wDoc.Name,".")) & "pdf",_
ExportFormat:=wdExportFormatPDF,OpenAfterExport:=False,_
OptimizeFor:=wdExportOptimizeForPrint,Range:=wdExportAllDocument,_
Item:=wdExportDocumentContent,IncludeDocProps:=True,KeepIRM:=True,_
CreateBookmarks:=wdExportCreateNoBookmarks,DocStructureTags:=True,_
BitmapMissingFonts:=True,UseISO19005_1:=False
wDoc.Close SaveChanges:=True
Next
Dim Answer
Answer = MsgBox("Update more files?",vbYesNo,"Run Macro?")
If Answer = vbYes Then
Call MassUpdate
End If
End Sub
解决方法
我怀疑这两个例程可能针对不同的文档。尝试修改您的 Demo 例程以将文档作为输入参数:
Sub Demo(targetDoc as Document)
Application.ScreenUpdating = False
Dim r As Long,c As Long
With targetDoc.Range
然后您将呼叫行修改为(无需使用呼叫):
Demo wDoc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。