+ Reply to Thread
Results 1 to 25 of 25

Save file as value of a cell

  1. #1
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Save file as value of a cell

    Hello Excel Forum

    I am working on a VBA code that does the following: any help or suggestions would be greatly appreciated. The idea is that the user fills out a template with information and when they are ready to save the file it saves the file with a new file name and closes the template without saving or changing the template in any way.

    On button press open the Save As window in excel
    In the Save As window where the file name is displayed I would like for it to display a file name taken from a value in a cell from a different worksheet.
    When the user presses save in the Save As window I would like the template document to close without saving and the document that was just saved to stay open with the new file name.

    Thank you
    Last edited by cm3pyro; 07-22-2010 at 04:19 PM.

  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: Save file as value of a cell

    When a true Excel Template is opened, you are in no danger of overwriting it because template files (when opened properly) open in a SaveAs only state.

    Save your excel document as an .XLT file so that it is a true template. Open it with a shortcut to it placed somewhere, or the FILE > NEW > Template option.

    Now SaveAs is your only option and your template is fine.

    ==========

    To get a default filename in the SaveAs dialog, put this macro into the ThisWorkbook module of your template:
    Please Login or Register  to view this content.
    _________________
    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
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    JBeaucaire

    Thank you! This works great.

    I have a few questions though.

    Is it possible to get the file name from a different excel document instead of from a sheet in the template document?
    Is it possible to have the Save As window navigate to a directory to save the file in?
    Example: F:\Engineering\

    Thanks

  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: Save file as value of a cell

    Quote Originally Posted by cm3pyro View Post
    Is it possible to get the file name from a different excel document instead of from a sheet in the template document?
    Please be very specific: Filepath, filename, sheetname, cell address


    Is it possible to have the Save As window navigate to a directory to save the file in?
    Example: F:\Engineering\
    Yes, I'll show both answers together.

  5. #5
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    Filepath: F:\Engineering\TEST RESULTS\PROCEDURES\REPORT TEMPLATES
    filename: Test Report Number Generator.xls
    sheetname: Report
    cell address: B15

  6. #6
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    Still around JBeaucaire?

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

    Re: Save file as value of a cell

    Try this:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    JBeaucaire

    I am still having some issues. The SaveAs window is not opening into F:\Engineering

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

    Re: Save file as value of a cell

    I just tried the macro as posted again and it opens to the path listed.

  10. #10
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    Quote Originally Posted by JBeaucaire View Post
    I just tried the macro as posted again and it opens to the path listed.
    I am still having issues resolving this problem. What would the procedures be to add this macro to a button on my report template so i can test it out that way?

    Thank you

  11. #11
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    i think i have discorded the problem! F:\ is a networked drive. when i change the code to navigate to a folder located on my C drive it works perfectly.

    And, is there any way to remove the quotes around the file name in the SaveAs window?

  12. #12
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    I figured it out, i added ChDrive "F:\" before the ChDir

    Now, is there any way to remove the " " from the file name in the SaveAs window?

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

    Re: Save file as value of a cell

    You do seem to get odd results. I don't get quotes around my strings in the Dialog box. Any chance the text strings in the cells being looked up have quotes around them?

    Maybe this, change this one line of code:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    This is the formula in the cell i am pulling the value from for the file name.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    Please Login or Register  to view this content.
    didnt work

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

    Re: Save file as value of a cell

    Here you go:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    JBeaucaire

    I am trying to put all of this code to use now and i am running into a pretty substantial problem. Everything works great but after the template file is filled out and automatically saved as a .xls when i need to edit that file it does not let me save the updated information.

    Is there a way to clear all of the VBA code once the template is filled out and saved as a .xls ..so there is no VBA code saved in the .xls document?

    Thanks

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

    Re: Save file as value of a cell

    I don't know why it won't let you, the code only invokes during a SAVEAS function. Any regular SAVE function should result in the file simply saving normally.

  19. #19
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    Please Login or Register  to view this content.
    Worked perfectly, thank you!

    Let my attempt to rephrase the issue i am having with saving the files created from the templates.

    After i use the template to create the file and save it, it is given a specific file name from the value in my test report number generator worksheet. This number in the file name changes for every test report. When i go back to update a test report made from the template, and when i click save the Save dialog box appears with the most recent file name generated by the file name generator..it does not simply just update the file when the saved button is clicked.

    The VBA code used in the template file is not necessary in the .xls workbook it creates, that's why i was wondering if it is possible to delete the vba code in the .xls document when it saved from the template for the first time.

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

    Re: Save file as value of a cell

    I understand the situation, it just doesn't make sense to me.

    The code does an IF SaveAsUI test at the beginning of the code. The only time it should do the "offer a new filename" trick is when you are doing a SAVEAS, not when you just do a normal save.

    When it's a normal save, it should just save.

    Upload one of the resulting files and let me look at it.

  21. #21
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    template: click here
    resulting file from template: click here

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

    Re: Save file as value of a cell

    Every time I press CTRL-S to save the A.xls file, it just saves. No popup.

    You could add this near top just after the DIMs, it should have been there all along:
    Please Login or Register  to view this content.

    ...and this as well:
    Please Login or Register  to view this content.
    As I said, when not doing a SaveAS, it should just save, and for me it does.
    Last edited by JBeaucaire; 07-21-2010 at 06:44 PM.

  23. #23
    Registered User
    Join Date
    07-12-2010
    Location
    LA, California
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Save file as value of a cell

    That fixed it! Here's the completed code. Thank you so much, you efforts are greatly appreciated.

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    09-09-2009
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    185

    Re: Save file as value of a cell

    Just subscribing to this post for future education and reference.

    Thank you.

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

    Re: Save file as value of a cell

    CM3, you can remove those same two lines you added at the top from inside the IF statement, they are unnecessarily duplicated there, sorry I didn't point that out earlier.

    ==========
    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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