+ Reply to Thread
Results 1 to 5 of 5

Saving Active Workbook as Variable

  1. #1
    Forum Contributor amyxkatexx's Avatar
    Join Date
    11-23-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2004 for Mac
    Posts
    128

    Saving Active Workbook as Variable

    Okay, so I have quite a few scenarios where I am needing within my macro to activate multiple workbooks.

    These workbooks are often named different names, including one of which I use regularly that is a template, so every time it opens, it has a number at the end of it.

    I had an epiphany that if there was a way that I could get excel to assign a variable name to an active workbook so that later in the code, it is able to go back to that workbook that is no longer active now because it has moved on to other workbooks since then, that would make life a whole lot easier.

    I googled a bit, but all I could find was code that activates workbooks.

    So in a nutshell, I am not needing a code that can activate a workbook. I need a code that can sort of grab whatever the name is of the current active workbook and allow me to use that later.

    Any ideas?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Saving Active Workbook as Variable

    Like so:
    Please Login or Register  to view this content.

    With this, you can use wbTemp as the template object through the rest of the macro.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor amyxkatexx's Avatar
    Join Date
    11-23-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2004 for Mac
    Posts
    128

    Re: Saving Active Workbook as Variable

    Okay, so right now I use this code to open the workbook.
    Please Login or Register  to view this content.

    I have some code before it and then more code after it. But at the end, I am wanting to go back to that open template to use it again.

    Where would I put that "Dim wbTemp as Workbook" part?

    Would it be like this? (your code is in bold)
    Please Login or Register  to view this content.

    And also, what would the activate workbook code look like using that object?

    Like this?
    Please Login or Register  to view this content.
    Last edited by amyxkatexx; 03-29-2010 at 03:35 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Saving Active Workbook as Variable

    Maybe like so...the wbTemp is an object, so you can use it as such, no need to try and nest it inside an Sheet reference.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Saving Active Workbook as Variable

    You generally do not need to activate workbooks,sheets or ranges

    If your workbook is actually a template (*.xlt) then when it opens it creates a new workbook (*.xls) based on the template. So each time your code opens the template a new workbook will be created so it will need renaming.

    Just a guess from your posted code
    Please Login or Register  to view this content.
    Last edited by royUK; 03-10-2010 at 02:41 AM.
    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)

Tags for this Thread

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