0

我正在尝试在文件夹中保存的 PDF 中包含文档标题。此 vba excel 文件将与 PDF 放置在同一文件夹中。下面的代码打开每个 PDF 添加 Title ,保存,关闭 PDF。但是,该代码还将第一个 PDF 的内容保存在剩余的 PDF 中。我不希望每个 PDF 的内容发生变化。我只想在每个 PDF 中包含标题。请让我知道缺少什么。

Sub Add_title()
    Dim phApp As FoxitPhantomPDF.FoxitApp      
    Dim Part1Document As FoxitPhantomPDF.FoxitAVDoc        
    Dim PDDoc As FoxitPhantomPDF.FoxitPDDoc
    
    Dim FilePath As String
    Dim n As Integer
    
    Set phApp = CreateObject("FoxitExch.App")        
    Set Part1Document = CreateObject("FoxitExch.AVDoc")
            
    FilePath = Dir(ThisWorkbook.Path & "\*.pdf")
    n = 0
    
    Dim Response As VbMsgBoxResult
    Response = MsgBox("Do you want to process all the files in the folder?", vbQuestion + vbYesNo)
    If Response = vbNo Then Exit Sub

    Do While Len(FilePath) > 0
        Call Part1Document.Open(ThisWorkbook.Path & "\" & FilePath, "")     
        Part1Document.GetPDDoc.SetInfo "Title", "TEST" 'Update title here     
        Part1Document.GetPDDoc.Save PDSaveFull, ThisWorkbook.Path & "\" & FilePath
        Part1Document.GetPDDoc.Close
        FilePath = Dir
        n = n + 1
    Loop

    'Part1Document.Close (False)

    phApp.Exit
    MsgBox (n & " files have been processed.")
End Sub
4

0 回答 0