Speed up macro that extracts text from PDF's in a directory

  • I have some code I combined from a couple sources that will open a bunch of pdf's in a directory using Word to extract a sentence of text and place it to excel. It works but is slow because it's opening and closing Word with each iteration. But when I try opening Word before the loop by moving Set WApp = CreateObject("Word.Application") before the start of the loop (and WPapp.Quit after it ends), I get a run time error saying the object is not set. Any advice on how to improve this appreciated.

  • This should work faster


    Cheers,

    --

    LR

  • Thanks Ardus, but that's what was causing my problem. I.e. setting Word before the loop caused the crash but inside the loop it would run. Anyway, I've since figured it out via debugging. It was hanging on WApp.Close. In debug mode ,the Save as window was popping up at that point and not being dealt with so the connection to word app was being broken but this was not apparent when just running it. Once I saved the first file it worked fine thereafter. So, now I can instantiate Word before the loop and all is well. Thank you so much for responding. Now I just need to find the close without saving command in word vba so it doesn't happen again. cheers

  • Hi Jaffey,


    Have you tried with:


    Code
    Application.DisplayAlerts = False
    
    Your Code
    
    Application.DisplayAlerts = True

    Not sure if this captures your problem, it would if excel were generating the save as prompt.


    Justin

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!