csv 从特定文本字段导出PDF值并将其导入Xls文件中的特定单元格

jfgube3f  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(73)

我有下面的宏,但它不工作.我已经安装了Adobe Acrobat Pro.从一个方面,我担心我没有拥有我需要的所有引用(这将是一个很大的帮助已经知道所需的引用列表和如何获得它们.例如,我没有Adobe Acrobat 10.0类型库.).
目前,我被错误卡住了:“对象不支持属性或方法”,引用行SHIPSNAME = pdfDoc.GetField(“SHIPSNAME CREWLIST”). Value。
拜托,拜托,让我走上正确的道路来解决这个问题。这对我的工作非常重要。

Sub ImportaDaPDF()

    ' Imposta il percorso del file PDF
    Dim pdfPath As String
    pdfPath = "C:\Users\@@@@\Desktop\Document.pdf"  ' Sostituisci con il percorso del tuo file PDF
    
    ' Crea un oggetto Acrobat
    Dim acrobatApp As Object
    Set acrobatApp = CreateObject("AcroExch.App")

    ' Crea un oggetto PDF
    Dim pdfDoc As Object
    Set pdfDoc = CreateObject("AcroExch.PDDoc")

    ' Apri il file PDF
    If pdfDoc.Open(pdfPath) Then

        ' Estrai i valori dai campi testo
        Dim SHIPSNAME As String
        SHIPSNAME = pdfDoc.GetField("SHIPSNAME CREWLIST").Value
        
        Dim FLAGSTATE As String
        FLAGSTATE = pdfDoc.GetField("FLAGSTATE CREWLIST").Value

        ' Chiudi il file PDF
        pdfDoc.Close

        ' Chiudi l'applicazione Acrobat
        acrobatApp.Exit

        ' Inserisci i valori nelle celle specifiche di Excel
        Dim wsShip As Worksheet
        Set wsShip = ThisWorkbook.Sheets("Page 1")  ' Sostituisci con il nome del tuo foglio
        wsShip.Range("A4").Value = SHIPSNAME

        ' Inserisci i valori nelle celle specifiche di Excel
        Dim wsPortCall As Worksheet
        Set wsPortCall = ThisWorkbook.Sheets("Page 2")  ' Sostituisci con il nome del tuo foglio
        wsPortCall.Range("B4").Value = FLAGSTATE

    Else

    MsgBox "Errore durante l'apertura del file PDF. Dettagli: " & Err.Description

End If

End Sub

字符串
我需要从我的PDF文档的特定文本字段中提取值,并将这些值导入到Xls文件的特定单元格中。我已经尝试过,首先,一个较长的过程,基本上我是将值作为文本发送到电子邮件的正文中,复制并粘贴到CSV文件中,但它不起作用,甚至一点也不起作用,因为我用来从CSV文件导入数据的宏在另一种情况下不起作用

pinkon5k

pinkon5k1#

这对我来说是一个测试PDF表单:

Private Sub ReadPdfFormFields()
    Dim jso As Object, text1, text2 As String
    
    With CreateObject("AcroExch.PDDoc")
        .Open "C:\temp\Test.pdf"        'load the file
        Set jso = .GetJSObject
        
        ' get the information from the form fields
        text1 = jso.getField("FieldNumber1").Value
        text2 = jso.getField("FieldNumber2").Value
    
        Debug.Print "Values read from PDF: " & vbLf & text1 & vbLf & text2
        .Close        'close the file
    End With
End Sub

字符串

相关问题