+ Reply to Thread
Results 1 to 3 of 3

how can i execute a macro in current workbook after another workbook opens?

  1. #1
    Registered User
    Join Date
    07-09-2014
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    10

    how can i execute a macro in current workbook after another workbook opens?

    Below is my code so far. It goes to a url, logs in, runs a search, downloads the results, and then the "Sendkeys" line at the very end hits enter and opens the file from the Internet explorer download prompt that asks whether I want to open or save the file. What I want to do is, when the report opens in excel, copy the data from the newly opened file into the file that the macro was run from. I've tried to add this:
    Please Login or Register  to view this content.
    where the M&A report generator file is the original workbook containing the macro, but I get "runtime error 9, subscript out of range". It seems to be executing the copy/paste before the new workbook opens. I've tried to put an application.wait in there too, but the same thing happens. It seems the workbook won't open until the entirety of my code finishes running. Can anyone offer any suggestions to make this work?


    Please Login or Register  to view this content.

    On a side note, in a previous iteration of the code I had all the
    Please Login or Register  to view this content.
    replaced with
    Please Login or Register  to view this content.
    but with it set up that way, I sometimes got errors when I would run it, and other times no errors. Anyone have any idea why?

    I'd prefer to have the do while mybrowser.ready state<>4 piece than the wait because it seems that it should be more reliable. Maybe I am not using it properly.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: how can i execute a macro in current workbook after another workbook opens?

    Hello sds1126,

    The problem is Internet Explorer runs independently of VBA. There is no way to sync VBA's and Internet Explorer 's operations together. Because of this, any method you employ will not be 100% reliable.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-09-2014
    Location
    Boston, MA
    MS-Off Ver
    2010
    Posts
    10

    Re: how can i execute a macro in current workbook after another workbook opens?

    Leith Ross, thank you for your prompt reply, I realize I asked two questions in my post and it seems you may be answering the second of the two? What I am most interested in is my first question, as to whether or not I can have a macro run when a second workbook is opened in excel. I know you can have a script run on the event of the workbook containing that script opening, so I wonder if there is a similar event that I could have trigger my second macro to copy and paste data.

+ 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: 3
    Last Post: 07-12-2014, 06:04 AM
  2. Replies: 1
    Last Post: 03-10-2014, 05:20 AM
  3. How to open,save and close another workbook from the current workbook using macro?
    By ravikumar00008 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-15-2012, 10:42 AM
  4. A button that opens a new workbook and saves the current worksheet on to it
    By shilpz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2008, 02:50 AM
  5. Execute Macros from Other workbooks on current workbook
    By Allen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2006, 09:10 PM

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