+ Reply to Thread
Results 1 to 8 of 8

Save as with variable file name and directory (simple no!)

  1. #1
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Save as with variable file name and directory (simple no!)

    Hi All,

    Have spent a few hours going through this forum again and cannot find my answer (Probably poor search technique))

    I have a macro that finishes by copying a sheet (tab) to a new work book.

    The problem comes when I try to save it. all the posts I have found hard code the file name and directory, these need to be selected by the users

    Below are many tries, all those with " ' " do not work

    attached is the output sheet that has to be saved (can't use template as to much sensitve data)

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Save as with variable file name and directory (simple no!)

    Please Login or Register  to view this content.
    should work fine. you probably want to replace activesheet with Sheets("IPLUS Output") if you want to do a specific sheet.
    Last edited by Leon V (AW); 08-14-2013 at 10:10 AM.

  3. #3
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Save as with variable file name and directory (simple no!)

    Thanks, not sure why this works now and not earlier

    Is not saving the file as .xlsx though, just a type "file" (not given a choice to select it either) and I have to select the program to open?

  4. #4
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Save as with variable file name and directory (simple no!)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Save as with variable file name and directory (simple no!)

    thanks guys,

    could you please explain how this works, as my limited understanding of "GetSaveAsFilename" means show me names I could use

  6. #6
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Save as with variable file name and directory (simple no!)

    http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    they explain it well enough.

    basically "GetSaveAsFilename" outputs a string combining the directory you selected and the filename you entered when you click save. It also limits what you can name the file as e.g. "\" as that would be seen as a folder by "Workbook.SaveAs"
    if you click cancel it outputs false.

  7. #7
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Save as with variable file name and directory (simple no!)

    Sorry, this is where I am confused. Your link states:

    Displays the standard Save As dialog box and gets a file name from the user without actually saving any files.

    How does the code allow the user to save the file

    Apologies for being slow

  8. #8
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Save as with variable file name and directory (simple no!)

    that bit doesn't. Application.GetSaveAsFilename is just that, a file name. It couldn't save anything if it wanted to as it is part of the excel "APPLICATION" and not any open workbooks.

    the file is saved on the last line of the code I supplied "ActiveWorkbook.SaveAs savingname" which saves the activeworkbook using the filename and location generated by "Application.GetSaveAsFilename" earlier in the code.

    you could think of "Application.GetSaveAsFilename" as just a "GetName" command with a "FileSaveType" character validation built into it

+ 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. Call in Variable File Directory and Filename from Cell into Save As Prompt
    By cyphus64 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2013, 09:37 PM
  2. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  3. Replies: 2
    Last Post: 01-16-2013, 03:10 PM
  4. Macro to save file in a specified directory and name
    By 4romseyavenue in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-27-2011, 12:09 PM
  5. Replies: 3
    Last Post: 06-11-2009, 07:08 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