+ Reply to Thread
Results 1 to 5 of 5

Importing PDF into Excel using VBA

  1. #1
    Registered User
    Join Date
    05-30-2018
    Location
    Los Angeles
    MS-Off Ver
    2016
    Posts
    8

    Post Importing PDF into Excel using VBA

    I have a PDF that has multiple tables (page header, detail, summary footer) and multiple pages. I am looking to import this PDF into Excel and keep the format with minor tweaking to the detail section.

    If I Export the PDF from Acrobat into Excel, the format does not come across. If I copy and paste from Acrobat to Excel, it does not keep, even if I use word as a middle layer.

    If in Excel I use Data->Get Data->From File -> From PDF, Excel comes back with 6 tables and three pages for the three page PDF. I can use this data, but need to access these tables via VBA.

    Is there a function in Excel or the Excel Acrobat API that I can use to bring these tables into Excel? Since the header is a page header, I only need Table 1 for the page header and table 2, 4 and 6 will have the footer info. If I could get these in Excel, I could write code to transform from this staging tab in excel to a final output.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Importing PDF into Excel using VBA

    Easy Peasy with Power Query which is part of your native excel.

    https://www.youtube.com/watch?v=C6vqy30PDnE
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    05-30-2018
    Location
    Los Angeles
    MS-Off Ver
    2016
    Posts
    8

    Re: Importing PDF into Excel using VBA

    [QUOTE=alansidman;5852937]Easy Peasy with Power Query which is part of your native excel.



    This is exactly what I am looking to use. I assume the Power Query commands are available via VBA? I'll do some research on this, but is there a good example to use?

  4. #4
    Registered User
    Join Date
    05-30-2018
    Location
    Los Angeles
    MS-Off Ver
    2016
    Posts
    8

    Re: Importing PDF into Excel using VBA

    So I was able to record a macro and get the code for my Power Query PDF Import.

    Please Login or Register  to view this content.
    This works pretty well for a known PDF page count, but I am wondering how to execute this for a dynamic PDF. The structure in the PDF will be the same, but the number of pages could differ

    I am new to Power Query code, but I am thinking it needs to be something along the lines of this process:
    1. User selects a file. That file is stored as the Data Source for that import. PDF Filename will change each time
    2. VBA code reads number of tables in selected PDF file via Pdf.Tables(File.Contents(""" & PDF_Path & """), [Implementation=""1.3""]) (I can do this with Advanced Editor Power Query M script, but need it in code)
    3. Queries are created (or run from stored queries) based on the number of tables.
    4. Data is entered into Excel via ActiveSheet.ListObjects.Add commands for each query

    The dynamic part is what I am having issues with. Is it possible to store a data Souce via VBA, then use that for queries and have all the variables in the query be dynamic? Same for entering into Excel

    Any good examples of this?
    Last edited by jharding; 07-25-2023 at 07:52 PM. Reason: Solved one issue

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Importing PDF into Excel using VBA

    crossposted: https://www.mrexcel.com/board/thread...ables.1241878/

    Rule 03: Cross-posting Without Telling Us

    Your post does not comply with Rule 3 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Read this to understand why we ask you to do this.

    I have added the crosspost reference for you today. Please comply with this and all our rules in the future

    However, if you continue to crosspost, you can expect to have your thread BLOCKED until you update it yourself.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-20-2017, 06:31 PM
  2. Replies: 7
    Last Post: 02-14-2014, 12:37 PM
  3. Adjust Layout and excel pastespecial , in words after importing from excel
    By andywsw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2012, 10:15 PM
  4. [Excel 2k3] Importing spreadsheet specs from Access Tables and Render it in Excel
    By iboumiza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2011, 01:19 AM
  5. Importing excel spreadsheet into access table, getting excel row header error
    By ncsthbell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2010, 02:36 PM
  6. Replies: 3
    Last Post: 03-04-2010, 02:20 AM
  7. Replies: 1
    Last Post: 01-27-2010, 03:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1