+ Reply to Thread
Results 1 to 5 of 5

Setting user-defined file name as variable and passing to workbooks?

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

    Setting user-defined file name as variable and passing to workbooks?

    Hi everyone,

    I am creating a macro that pulls data from three separate workbooks and combines that data into one book. To do this I have a user form where the source files are set and a destination file and path are assigned by the user. I have created the form which you can run by clicking the cmd button on the first sheet of the attached book. I have the user assign the destination and file name at the bottom of the userform and then the macro pulls that.

    Here is the code from the userform:

    Please Login or Register  to view this content.
    This is only the beginnings of my macro so I am ignoring the other text boxes on the form for now and just trying to get a single source to work all the way through. Once I copy the template sheet, I need to paste it as the first sheet in the new book the user just created. But the macro hangs on the .copy line I think because the variable "DestSource" isn't working?


    Any advice on how to reference the newly created workbook later in the code since the name changes each time?

    I know I could put the "GetSaveAsFilename" into code like so and lose the destination from my userform:

    Please Login or Register  to view this content.
    But how would I make that new file the user creates a variable and later reference it to copy sheets into? This way seems more direct that the userform route, so maybe some of you experts could advise me on the most efficient method of acquiring the destination file and path from the user in a way that is referable throughout the macro.

    Thanks for the help!
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Setting userdefined file name as varaible and passing to workbooks?

    Hello magicbob0007,

    Can you explain more what happens when Excel hangs and what you have to do afterwards?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: Setting userdefined file name as varaible and passing to workbooks?

    yea. I set the destination and file name to my desktop, click create the summary, and the new file opens renames to the name I provided, and then i get:

    Run-time error '9':

    Subscript out of range

    When I click debug, the line after my comment is highlighted. And the userform is stuck, so I have to click the reset button in the visual basic editor to do anything.

    So its working as I want up to the copy line.

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

    Re: Setting userdefined file name as varaible and passing to workbooks?

    oh wait...now that I am looking at this after taking a break...could the issue be that the variable "DestSource" is defined as a string? so it works fine as a file name and path but not as a location?

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

    Re: Setting user-defined file name as variable and passing to workbooks?

    no thats not it

+ 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