使用VBA将PDF阅读(仅限Acrobat Reader DC)到Excel

时间:2019-07-25 16:51:02

标签: excel vba pdf acrobat

Tryinf使用VBA代码将PDF数据读入excel。我只能在工作计算机上访问Adobe Reader DC。

我尝试了以下代码

Sub ReadAdobeFields()

 Dim AcrobatApplication As Acrobat.CAcroApp
 Dim ArcrobatDocument As Acrobat.CAcroAVDoc
 Dim fcount As Long

 Dim sFields As String

 On Error Resume Next

 Set AcrobatApplication = CreateObject("AcroExch.App")
 Set AcrobatDocument = CreateObject("AcroExch.AVDoc")

 If AcrobatDocument.Open("C:\Users\Desktop\Summary.pdf", "") Then

      AcrobatApplication.Show
      Set AcroForm = CreateObject("AFormatAut.App")
      Set Fields = AcroForm.Fields
      fcount = Fields.Count

      For Each Field In Fields
       row_number = row_number + 1
       sFieldName = Field.Name

       Sheet1.Range("B" & row_number) = Field.Name
       Sheet1.Range("C" & row_number) = Field.Value
       Sheet1.Range("D" & row_number) = Field.Style

      Next Field

      Else

        MsgBox "Failure"


    End If

    AcrobatApplication.Exit
    Set Arcobat.Application = Nothing
    Set Acrobat.Document = Nothing
    Set Field = Nothing
    Set Fields = Nothing
    Set AcroForm = Nothing

End Sub

预期结果将是成功读取PDF文件数据并使用VBA编码将其置于excel格式。

0 个答案:

没有答案