Save As Error Handling Through Input Box

  • I need to:

    • Turn off "save" and "save as" command bars
    • Prompt user for a unique filename
    • Save file to a specific directory on the network common to all "p:\data\prc"
    • Requery user if filename exists and if they DON'T want to overwrite.
    • Return to worksheet (there is only one) if the user cancels from the message box.
    • Turn commandbars back on


    The macro runs from an on screen button
    I get bug errors on NO or CANCEL when clicked in the message box
    This is my current code:



    I am a very proficient user of Excel but just starting out with VBA. Thank You very much.

  • Re: Save As Error Handling Through Input Box


    Hi there,


    Put the following code:

    Code
    If NewName = "" Then
            Exit Sub
            End If


    directly underneath this line of existing code:

    Code
    NewName = Application.InputBox(Prompt:="Please enter a UNIQUE filename without the .xls.", Type:=1 + 2)


    Cheers,


    Robert
    : D


    HTH

  • Re: Save As Error Handling Through Input Box


    Robert - I input your code but I get the following failure when clicking on No or Cancel:
    Run-time error '1004':
    Method 'SaveAs' of object '-Workbook' failed


    :(

  • Re: Save As Error Handling Through Input Box


    Hi there,


    Seems strange as it worked for me. You have mentioned the No button, do mean the OK button?


    That said, you could simplify your SaveMe macro by just calling (opening) the the built-in Save As dialog box once you've specified your desired directory as follows:


    Code
    BaseDir = "p:\data\prc"
        ChDir BaseDir    
    Application.Dialogs(xlDialogSaveAs).Show


    You then don't have to build in any error trapping as it's already there.


    Kind regards,


    Robert
    : D


    HTH

  • Re: Save As Error Handling Through Input Box


    Very simple solution Robert. It does what I need it to do.:)


    Is there a way that I can clear the default filename so they don't over write the original? The Excel workbook works by the user opening the file and filling in a bunch of unprotected cells. The problem I have is that some users don't take the time to enter a unique filename.


    Thank You - this forum is great and allows me to learn quickly.

  • Re: Save As Error Handling Through Input Box


    The user will be asked to verify if they want to overwrite the original if they don't change the filename and click the Save button on the Save As dialog box. If this isn't sufficient, you may have to find a way to disable the Save button on the Save As dialog box until a different filename is entered then enable the Save button - which I don't know how to do I'm afraid.

  • Re: Save As Error Handling Through Input Box


    Thanks for sticking this out with me. I have a working prototype and have put it into use. I will continue to work on how to clear the default filename or disable the command bar save functions.


    :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!