VBA Code to Extract Text from a PDF File in Excel

Extracting text from a PDF file directly using VBA in Excel is not a built-in functionality. However, you can achieve this by utilizing third-party libraries or tools. One popular library is “Adobe Acrobat” that provides an API called “Adobe Acrobat DC SDK” which can be used to extract text from PDF files programmatically.

Here’s an example of VBA code that uses the Adobe Acrobat library to extract text from a PDF file:

VBA Code:

Sub ExtractTextFromPDF()
    Dim acApp As Object ' Adobe Acrobat application object
    Dim acDoc As Object ' Adobe Acrobat document object
    Dim acPage As Object ' Adobe Acrobat page object
    Dim text As String ' Variable to store extracted text
    
    ' Create new instances of Adobe Acrobat objects
    Set acApp = CreateObject("AcroExch.App")
    Set acDoc = CreateObject("AcroExch.PDDoc")
    
    ' Open the PDF file
    If acDoc.Open("C:\Path\to\your\file.pdf") Then
        ' Extract text from each page
        For i = 0 To acDoc.GetNumPages - 1
            Set acPage = acDoc.AcquirePage(i)
            text = text & acPage.GetWordText & vbCrLf
        Next i
        
        ' Display the extracted text
        MsgBox text
        
        ' Close the PDF file
        acDoc.Close
    Else
        MsgBox "Failed to open the PDF file."
    End If
    
    ' Release the Adobe Acrobat objects
    Set acPage = Nothing
    Set acDoc = Nothing
    Set acApp = Nothing
End Sub


Check All VBA Codes

Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author) 📞 +91 9536250020
[MBA in Finance]

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He is running this website (TechGuruPlus.com) and a YouTube channel called "Business Excel" since 2016. He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment