+ Reply to Thread
Results 1 to 10 of 10

Create a Command Button to "Save As" and "Close" an Excel Workbook

  1. #1
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Tacoma, Washingtonn
    MS-Off Ver
    Excel 2019
    Posts
    254

    Create a Command Button to "Save As" and "Close" an Excel Workbook

    Greetings everyone,

    I have, what I thought should be, a rather simple project. After two days of fumbling around, I need help.

    I have a workbook that I use over and over again. What I would like to do is...after entering all the data, save the workbook in a designated folder on my desktop as a file name (entered on sheet 1 in cell K3), and then simultaneously close the workbook. When the workbook is opened for the next event it will be blank and ready for new data. Sort of like a template, but not a template in the true sense. It would be rare for the file name to already exist, but if it did, Maybe a prompt to overwrite might be helpful.

    Thanks in advance for any help. This forum has been a tremendous resource for me in the past. The users are knowledgeable and friendly.

    Jim

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    See the attached.
    Attached Files Attached Files
    Gary's Student

  3. #3
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Tacoma, Washingtonn
    MS-Off Ver
    Excel 2019
    Posts
    254

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    Jakobshavn, thanks so much for your quick reply. I used the code but it is telling me it cannot be saved as a macro-enabled workbook. Is there one piece missing so that it saves as a .xlsm?

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    Make sure you have updated the filepath in the VBA to point to a folder on your desktop.

  5. #5
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Tacoma, Washingtonn
    MS-Off Ver
    Excel 2019
    Posts
    254

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    I think the path is right. Popup box says "The following features cannot be saved in Macro-free Workbooks: .VB Project To save a file with these features, click No and then choose Macro-enabled file type in the file type list. To continue to save as a Macro-free workbook click Yes.

    Did I insert something somewhere that I need to remove? .VB Project?

  6. #6
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    I get your error message if K3 contains:

    Book1.xlsx
    rather than
    Book1.xlsm


    check cell K3

  7. #7
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Tacoma, Washingtonn
    MS-Off Ver
    Excel 2019
    Posts
    254

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    I seem to have it about 99% working. The earlier problem was that I never did save my original workbook as .xlsm. Once I did that things started working. One final glitch...the command button closes and saves the file okay, but excel never fully shuts down. The grey background of excel is still on the screen until I "x" close it. Also, as a final request. Is there a function that will disable the command button in the saved copy? Probably not, but I just didn't want the user to inadvertently save & close the saved copy over and over again. Thanks again for all your help, I'v accomplished more in the past couple of hours than the last two days.

  8. #8
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    The first issue can be addressed by replacing:
    ThisWorkbook.Close
    with:
    Application.Quit

    in the button code.

    I don't know how to disable the button the saved version

  9. #9
    Forum Contributor
    Join Date
    08-19-2012
    Location
    Tacoma, Washingtonn
    MS-Off Ver
    Excel 2019
    Posts
    254

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    Thank you so much for your help! It's working perfectly now. Just a quick question for my own education. When I add a field, formatting a few cells as currency ($8 for example) it returns an error when I hit the command button. Is there an easy way around that or should I just leave it alone? Not a big deal really, just for looks... Thanks again!!!

  10. #10
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Create a Command Button to "Save As" and "Close" an Excel Workbook

    Very odd..................I can't reproduce you problem.

+ 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