+ Reply to Thread
Results 1 to 3 of 3

Writing ActiveWorkbook Name To A Variable

  1. #1
    Registered User
    Join Date
    01-12-2014
    Location
    Plano, Tx
    MS-Off Ver
    Excel 2007
    Posts
    54

    Writing ActiveWorkbook Name To A Variable

    I run the macro on a currently open workbook (name could be anything) and open another workbook (name known) and step through the sheets copying various blocks of data across to the first workbook. I need to Activate the 2 workbooks alternatively as I move data back and forth and move from sheet to sheet. What I can't work out is how to determine in code what the "unknown" workbook name is so that I can make sure I activate the right workbook in the code.

    I tried Activating the workbook with the "unknown" name and setting a variable = ActiveWorkbook.Name. However the value of this variable changes during the code run when you activate the other book. Is there any way to collect this value and "freeze" it so it won't change as the code runs? I get a Run-Time error '9' Subscript out of Range on the line: ActiveWorkbook.Sheets("Weekly Food Cost").Activate
    Any help would be greatly appreciated
    Here is the code:

    Please Login or Register  to view this content.
    Last edited by arlu1201; 01-13-2014 at 01:40 AM. Reason: Use code tags in future.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Writing ActiveWorkbook Name To A Variable

    I cannot devise what you want done from your code.

    Below is example code of how to assign a workbook\worksheet to a variable, copy values between workbooks without activating or selecting, and close the original workbook. Perhaps you can incorporate the example to your situation.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    01-12-2014
    Location
    Plano, Tx
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Writing ActiveWorkbook Name To A Variable

    Thank you very much. I will give that a try.

+ 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. Variable Activeworkbook.worksheet names
    By dajsile in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2011, 08:05 PM
  2. ActiveWorkbook.Worksheets and variable Range
    By lionatucla in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2010, 01:06 PM
  3. Writing ActiveWorkbook Name to a variable
    By toveyj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2009, 12:15 PM
  4. [SOLVED] set variable to activeworkbook
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2006, 03:25 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