Closed Thread
Results 1 to 14 of 14

automatically produce save as file name by value in a cell

  1. #1
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    automatically produce save as file name by value in a cell

    I would like excel to automatically suggest the save as file name and location for my workbook when I click the save, save as or close options. The file name should be a combination of values in cells A1 and A2 of Sheet1. The location should be a folder named "Bill" in C:/My Documents. I think I can do it with a beforesave code but I am new to vba. Please help me.
    Last edited by dittotharappel; 03-22-2009 at 01:43 PM.

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

    Re: automatically produce save as file name by value in a cell

    Something like this, make sure that the path is correct
    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

  3. #3
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    Thanks, but that doesn't work. Neither the filename nor the save folder appear automatically. I am working with Office 2007. I want to save the file with extension .xls and not as xlsx. Is it a problem with the default file format. The default format is .xlsx.
    Last edited by dittotharappel; 03-21-2009 at 05:18 AM.

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

    Re: automatically produce save as file name by value in a cell

    What do you mean "appear automatically", do you want the saveas file dialog to appear?

  5. #5
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    Exactly. And thanks for the reply. I would like if the save as dialog box appears with the filename and the folder C:/Bill. If the folder doesn't exist "create it now?" should appear.
    Sometimes but not always error 1004 appears when I choose the save as option. When I debug the line
    ThisWorkbook.SaveAs fPath & Application.PathSeparator & fName & ".xls"
    gets highlighted. But I have the folder right there and it is not write protected.
    Last edited by dittotharappel; 03-21-2009 at 06:54 AM.

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

    Re: automatically produce save as file name by value in a cell

    Your initial question didn't say that at all. The code tha i gave you simply automates the save wihout showing the dialog.

  7. #7
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    I am sorry for the lack of clarity.

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

    Re: automatically produce save as file name by value in a cell

    This should do what you need
    Please Login or Register  to view this content.
    Last edited by royUK; 03-21-2009 at 05:09 PM.

  9. #9
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    It works the first time. But if the folder is already created it returns an error. This is what I did: I put the code in a new module and inserted the following code in This Workbook object:
    Please Login or Register  to view this content.

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

    Re: automatically produce save as file name by value in a cell

    Try this ameneded code
    Please Login or Register  to view this content.
    I've also changed the main macro
    Please Login or Register  to view this content.
    Last edited by royUK; 03-22-2009 at 12:51 PM.

  11. #11
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    That is excellent. Thanks a lot.

  12. #12
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    On checking it once again there seems to be a minor problem. In the save as dialog box if i click cancel the macro doesn't work anymore. I have to close and reopen the file to make the macro available again.

  13. #13
    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: automatically produce save as file name by value in a cell

    A little tweak:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  14. #14
    Registered User
    Join Date
    03-14-2009
    Location
    kerala, india
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: automatically produce save as file name by value in a cell

    Now it tries to save in the "My Documents" folder but throws up an error message. But using the first piece of code
    Please Login or Register  to view this content.
    with the beforesave code I had been using, ie,
    Please Login or Register  to view this content.
    produces the desired result without any error. I am a newbie to vba and so I dont understand why. Perhaps you will be able to tell me why. If you can explain it will be enlightening to us all. Thanks a lot for your prolonged help, royUK and shg. Without you I would still be groping in the dark.
    Last edited by dittotharappel; 03-25-2009 at 10:06 AM.

Closed 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