+ Reply to Thread
Results 1 to 5 of 5

Switch between 2 open workbooks in a macro without hardcoding the filename

  1. #1
    Registered User
    Join Date
    06-28-2007
    Posts
    6

    Switch between 2 open workbooks in a macro without hardcoding the filename

    I am working on a budget model where the model workbook is a read only file and it allows the user to select the data workbook they want to work on. This sub routine copies all of the data from the data workbook into the model workbook. I am using the Application.GetOpenFilename command to open the data workbook. That works fine. My problem is after the user has entered all of there budget data, I want to copy the data they just entered back to the data workbook and save it so the next time they go back into the model their data is where they left off. I can't get the sub routinue to do this part without having to use the Application.GetOpenFilename again in the code. This brings up the file open box again and they have to select the same data workbook they selected when they began or risk writing over another file.

    How can I get the copy back data to switch to the between the open workbooks?

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    Try something like this?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-28-2007
    Posts
    6

    Switch between 2 open workbooks in a macro without hardcoding the filename

    Thanks. This code works when the model workbook is opened and it copies the data from the data workbook into my model workbook but how do I keep the new filename when I leave that sub routine and start another one so that I can copy the data entered into the model workbook back to the data workbook

  4. #4
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    You can set it as a public variable... something like this:

    Please Login or Register  to view this content.
    Before your "Sub"

    That way whatever it is set to will carry over to each sub (as far as I can tell).

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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