+ Reply to Thread
Results 1 to 4 of 4

Reference user created work book later in code? GetSaveAsFilename

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Reference user created work book later in code? GetSaveAsFilename

    Hi gurus,

    I am starting to construct a bit of code that will filter criteria in a table on one sheet, copy the filtered data, and paste it to a new workbook that that user specifies the name of. So far I have this:

    Please Login or Register  to view this content.
    Everything works fine up to line 26:

    Please Login or Register  to view this content.
    I am using explicit references to the source workbook and worksheet for now. I know that the "sFileName" variable stores the path and file name the user specifies, but how can I reference the newly created workbook if using the variable "sFileName" isn't allowed? How do I go about activating the new spreadsheet since the name will be provided by the user and is not explicit? I suppose I could reference the workbook index but I would prefer a more fool proof method that directly references the new workbook the user just provided.

    Thanks for the help,

    Magicbob007

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Reference user created work book later in code? GetSaveAsFilename

    Hi

    As the variable has the full file name, including the path, you will have to strip out the workbook name part from the full. One way
    Please Login or Register  to view this content.
    rylo

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Reference user created work book later in code? GetSaveAsFilename

    You can use the workbook variable:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    11-09-2011
    Location
    San Diego
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Reference user created work book later in code? GetSaveAsFilename

    I actually just had a light bulb moment when I realized I store the active workbook name as a variable, so I came up with this and it gets the job done since its executed in the right order:

    Please Login or Register  to view this content.
    seems to happen every time I post something, I figure it out ten seconds after clicking submit even though I spend half an hour trolling the forum for a solution first. Thanks though!!
    Last edited by magicbob007; 06-19-2012 at 08:49 PM.

+ 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