+ Reply to Thread
Results 1 to 5 of 5

Macro doesn't work with another workbook acitive

  1. #1
    Registered User
    Join Date
    02-18-2012
    Location
    Bel Air, MD
    MS-Off Ver
    Excel 2010
    Posts
    13

    Macro doesn't work with another workbook acitive

    The macro below runs fine until another workbook is the active workbook. What can I do to change this macro to make it work while I have another workbook open and active. The macro works fine as long as the workbook to which it belongs is the active workbook. It will halt on the line beginning with Set rnAR_Dest with an Error 9 Subscript out of range.


    Please Login or Register  to view this content.
    Last edited by kioolt; 04-24-2014 at 12:07 AM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro doesn't work with another workbook acitive

    You would need to declare the workbook infront of the worksheet. Without it you will always be referencing the active workbook. Example:

    Please Login or Register  to view this content.
    Note the use of the extension. You will need too apply it where neccessary

  3. #3
    Registered User
    Join Date
    02-18-2012
    Location
    Bel Air, MD
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Macro doesn't work with another workbook acitive

    That did the trick. I had to apply it to about half a dozen places. Is there a way to get the workbook name that this module is in? The name of the workbook is "MyWorkbook 2014". Next year I will start with the data removed and have a new workbook named "MyWorkbook 2015". It's not much trouble but I will have to change the macro every year unless I can insert code that will use the right name for me. Something WorkBookName = Workbooks.Name, which I tired but doesn't work.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro doesn't work with another workbook acitive

    Hi, kioolt,

    please add code-tags to your procedure in the opening post.

    If the workbook holds the code as well you could rely on ThisWorkbook instead of Workbooks("MyWorkbook 2014.xlsm").

    Ciao,
    Holger
    Last edited by HaHoBe; 04-24-2014 at 12:18 AM. Reason: corrected Workbook to Workbooks
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    02-18-2012
    Location
    Bel Air, MD
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Macro doesn't work with another workbook acitive

    Thanks,

    Using ThisWorkbook is working just fine.

+ 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. [SOLVED] Macro work in personal workbook, doesn't work in other workbooks
    By Centexcel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2013, 11:47 AM
  2. macro to copy cells to a new workbook doesn't work properly
    By dileva in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2013, 10:55 AM
  3. [SOLVED] Event macro runs in wrong workbook/doesn't work properly
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2012, 11:28 AM
  4. [SOLVED] Macro doesn't work when workbook is renamed
    By tandi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2012, 01:13 PM
  5. Macro that should create csvs of all the sheets of a workbook doesn't work! help!
    By scantron in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2012, 12:46 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