+ Reply to Thread
Results 1 to 4 of 4

Thread: Overwrite File If Select NO

  1. #1
    Registered User
    Join Date
    09-30-2009
    Location
    Alexandria, VA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Overwrite File If Select NO

    Hi,

    I know I can turn off the alerts by using

    Application.DisplayAlerts = False
              Application.DisplayAlerts = True
    However, in a particular juncture in the macro I don't want to turn off the alerts, if people are overwriting the file they should be prompted, if they select YES then the macro should continue (and it does), however if they select no it prompts the DEBUGGER.

    I want a Msg Box to pop up if they select no that says: YOUR PLAN WAS NOT SUBMITTED.

    How can I do that? Thanks for any help!!!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Overwrite File If Select NO

    Hello gophins,

    Here is an example.
      If Answer = "No" Then
         MsgBox "Your Plan was Not Submitted."
         'Add code here for what you want to do next
      End If
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-30-2009
    Location
    Alexandria, VA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Overwrite File If Select NO

    But what if the prompt is not mine, it is excel's, so when I say
        If Answer = "No" Then
    MsgBox "Your Plan was Not Submitted."
    I'm not really responding to a msg box that I created. So when Excel prompts: A filne named X already exists... Do you want to replace it? If I select yes, the macro continues (which is what I want), if people select No or Cancel, I want them to be prompted with the Msg Box "Your Plan was Not Submitted." and then Exit Sub.

    I don't know if I'm explaining it right...

    Thanks
    Attached Images Attached Images

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Overwrite File If Select NO

    Hello gophins,

    You don't need to respond to this dialog, you need to prevent it from being displayed. You're getting this message because of an error that can be avoided. You only need to test if the file or folder exists before you attempt to create it.
       If Dir("J:\MyFile.xls") <> "" Then
          'Code here to deal with prexisting file 
       Else
          'Code to create new file
       End If
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0