VBA to read contents from PDF File - VBA PDF Automation-3

VBA to read contents from PDF File - VBA PDF Automation-3 Before we start writing the code let's quickly copy the file path and now I'm gonna create a new workbook let's insert a new module and create a public constant variable called PDF underscore.

File and we'll store our file path here we'll create a sub procedure called read from PDF and before we start writing the code we'll reference it to Adobe Acrobat library just make sure you reference it.

To the latest version I have 10.0 there now let's start declaring variables the app will be our acrobat application every document this will be our acrobat viewer now let's replicate this for PDF.

Dog this will be PD dog and select X variable again all these are object variables in the page we're gonna select the text later this is for the page corner and the text corner we're going.

To look through later on we're gonna use this and then this will be the page numbered content please content and the content itself within the page now let's set the variables creating object.

We'll create an object for a VAR a B dock as well now we'll open the PDF document adding a quick handler in case if it fails to open it will exit sup now we'll try to.

VBA to read contents from PDF File - VBA PDF Automation-3

Reference and get the active document in this slow I'm gonna add a reference to get the active document from the application Hey app is okay now I'm gonna reference this PDF RP a PDF.

Underscore dog to the AV dog then we'll be exposed to the methods from the from the AV dog for PDF talk now I'm gonna look true from for all the pages the counter start from zero we'll have to.

Subtract one from the pages so within this look we're gonna reference I will create this page page number content and and so on okay creating an object again for page.

Content this is this particular object is basically gonna highlight highlight tags or contents within the page and then we'll discounters is basically we're selecting all the text from 0 to.

9,000 you might want to add more if your page have more condensed adding a quick error handler in case it returns an error when we try to select the text within the page.

Select Isis using the page highlight page content from the page content okay now we'll start looping through all the all the text within from the selection or j.j counter is going to take care of.

Posts Related:

    That again looping from 0 till all the

    Total and let's print this value to our immediate window that's pretty much it our we're gonna review it later after we write everything let's quickly clean the.

    Memory so make sure that once it finished running it clears out the memory so the next time it runs it's ok we're gonna close the PDF document there without saving it false stands for that.

    We're gonna exit the application and then we're just gonna set all these variables to nothing all the object variables so I keep on compiling there just to.

    Make sure that it compiles okay though this art hard party API is so it might even if it compiles okay maybe it will not be 100% working but then we'll have to run and test it out quickly we'll.

    Have to change this from read from PDF the typos and looks like we have to add it should be yeah it should be big content add okay so let's quickly check out our code and make sure it's working.

    I'm gonna quickly turn on the immediate window and try to run this code so I'm gonna hit f8 and quickly go through the code so it's starting to print out the data from PDF okay I'm gonna run the.

    Rest of the code let's extract all the data but since it's too much of data really doesn't make sense we print it out here in a mediate window let's try to transfer the same data to the to the.

    Worksheet here just say range let's print this out to column a okay I think that should do Oh call this PDF and I'm gonna execute this it's super quick it extracted all the data now I'm gonna.

    Quickly open the PDF file and do a quick recon so as you can see here the top flows report and the date is here in the PDF and then the Adobe Acrobat is this the paragraph starting from here and.

    Then so on so as you can see the data

    That is being pulled from PDF is not coming in the exact format that we need so in the following video we're gonna put in some additional logics to pull in.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continue tomake videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=ZWizyQ8_9s0
Previous Post Next Post