1

我正在研究一个 VBA 宏,该宏循环遍历一个大型电子表格,将每一行导出为 XML,将 XML 文件导入 PDF 表单(XFA 架构),然后将每个填充的表单保存到预定义的文件夹中。问题是,经过 96 次迭代(反复测试),每个新完成的 PDF 都会导致最旧的 PDF 从文件夹中消失。被循环的代码如下:

Sub AcroExport()

Dim OutputPath As String
Dim theForma As New AcroAVDoc
Dim theform As AcroPDDoc
Dim jso As Object
OutputPath = GetMyDocuments()

ActiveWorkbook.XmlMaps("1042-S_Map").Export OutputPath & "f1042sExportTemp.xml", True

If theForma.Open("C:\Users\E050704\Desktop\f1042s.pdf", "") Then

    Set theform = theForma.GetPDDoc
    Set jso = theform.GetJSObject
    jso.importXFAData OutputPath & "f1042sExportTemp.xml"
    theform.Save 1, OutputPath & "1042-S_K-1_Output\" & "Form 1042-S - " & Range("ReciptNameCell").Value & ".pdf"
    theForma.Close True

End If

End Sub

我还尝试了 JavaScript 对象中的 SaveAs 方法,结果略有不同(仍然是 96 个文件,但不是删除最旧的文件,而是根本不创建新文件)。

完全不知道如何让它保留超过 96 个文件。任何帮助深表感谢。

作为参考,我使用的是 Windows 7 Enterprise、Excel 2007 和 Acrobat 9 Standard(版本 9.4.6)。

4

0 回答 0