+ Reply to Thread
Results 1 to 3 of 3

VBA Refreshing macro w/ 2 workbooks open

  1. #1
    Registered User
    Join Date
    06-16-2008
    Posts
    43

    VBA Refreshing macro w/ 2 workbooks open

    I've searched for an answer for this for about the last week, I cant seem to find it. My problem is I have a workbook with a macro that is ran automatically every 15 seconds (or manually via a 'refresh' button). The workbook works fine when opened by itself, and when its opened on top of any other workbooks.

    The problem arises when I have atleast 2 excel sheets open and have the workbook with the timing macro in the background and another workbook on the screen. I get the error "run-time error '9': subscript out of range"

    when I hit debug this is the code that is highlighted
    Please Login or Register  to view this content.
    I have the "set wb = ('name of wb')" in my code. As suggested in a previous attempt to solve this problem.

    Below is the code im running. Its purpose is to update the sheet named 'summary' with information from other sheets in the same workbook.
    Please Login or Register  to view this content.
    also of note, it doesnt matter if the other workbook has macros in it or not, i still recieve the error screen

    [EDIT] Running Excel 2007, file is saved as a 'Excel Macro Enabled' workbook [/Edit]

    Like I said I've been looking everywhere for a solution to this. If anyone can point me in the right direction I would appreciate it. ~TIA
    Last edited by crizzle; 07-09-2008 at 02:59 PM.

  2. #2
    Forum Contributor
    Join Date
    06-14-2008
    Posts
    153
    Hi,

    I did a test on your macro and realized that this problem occurs when the summary sheet is missing.
    This means that the macro is running on the wrong workbook.
    So I did qualify every reference to "sheets" with the workbook name like this: "wb.sheets" and the macro ran fine.

    See the modified code, give it a try and let me know please.

    Regards.
    Please Login or Register  to view this content.
    Last edited by se1429; 07-09-2008 at 04:32 PM.
    Welcome to: http://www.exceldigest.com/myblog/
    "Excel help for the rest of us"

  3. #3
    Registered User
    Join Date
    06-16-2008
    Posts
    43
    yea that seems to have fixed the error screen from popping up, and the macro will run if its opened with another non macro enabled worksheet on top of it. The only weird thing is if I have two workbooks with the same macro but linked to the different book, when i try to close one, and keep the other opened it will reopen the other workbook. Strange... but its not that big of a deal. Thanks for all the help =)

+ 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