+ Reply to Thread
Results 1 to 3 of 3

Run Macro on Multiple OPEN Workbooks

  1. #1
    Registered User
    Join Date
    05-25-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2019
    Posts
    27

    Question Run Macro on Multiple OPEN Workbooks

    I'm using Able2ExtractPro to convert a PDF into EXCEL by invoking this from a macro-enabled workbook and I want to continue to run the macro on the newly opened "Book1.xls" created by Able2ExtractPro. However, the code operates on my macro-enabled workbook and not on the said "Book1.xls"

    How do I make sure that the code runs on the correct workbook and not just the one containing the macro?
    My code works if I copy and paste it into the target workbook, but I want to avoid this if possible.

    I will want to run this procedure on several open workbooks simultaneously to accomplish my goal.

    Cheers, DrEcosse

  2. #2
    Registered User
    Join Date
    10-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Run Macro on Multiple OPEN Workbooks

    You could identify what workbook you want the code to work for each time you make a reference as seen in the example below.

    Please Login or Register  to view this content.
    However, if you do that and you already opened a blank workbook before the new one was made, the workbook that you create will be Book2 or whatever the next number is. If you run the code so that no other workbook will be opened from the time you create the workbook and the time you run your code, you could do something similar to the code below in each reference.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-25-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2019
    Posts
    27

    Re: Run Macro on Multiple OPEN Workbooks

    Thanks Snax. The problem I faced is because Able2ExtractPro runs from the shell command and therefore opens a new session of Excel so my macro can't see it. I solved the issue by simply saving the converted file as "Book1.xls" in my working directory, then just used Application.GetOpenFilename to fetch my file.

    However, it would have been neater and tidier to have been able to access the already opened file without having to resort to a save first. If someone can tell me if that's possible or not, that would be much appreciated.

    Many thanks for your input, with best regards.

    DrEcosse

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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