+ Reply to Thread
Results 1 to 8 of 8

How check for No/Cancel Button when SaveAs and file already exists?

  1. #1
    Joe HM
    Guest

    How check for No/Cancel Button when SaveAs and file already exists?

    Hello -

    I have a quick question: I use the ThisWorkbook.SaveAs function to
    save a file but if the file already exists, Excel shows a warning. The
    problem is that if I say either No or Cancel, there is an exception
    thrown. How can I catch the result of that MsgBox()?

    Thanks!
    Joe


  2. #2
    Bob Phillips
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    Joe,

    What are you tryin g to do, not save it if it already exists? If so, try
    trapping it, and don't save if so

    Function FileExists(sFilename As String) As Boolean
    FileExists = Dir(sFilename) <> ""
    End Function



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Joe HM" <[email protected]> wrote in message
    news:[email protected]...
    > Hello -
    >
    > I have a quick question: I use the ThisWorkbook.SaveAs function to
    > save a file but if the file already exists, Excel shows a warning. The
    > problem is that if I say either No or Cancel, there is an exception
    > thrown. How can I catch the result of that MsgBox()?
    >
    > Thanks!
    > Joe
    >




  3. #3
    Joe HM
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    Hello -

    I get an error if I press either No or Cancel in the prompt that Excel
    will show if the file already exists:
    Run-time error '1004'
    Method 'SaveAs' of object '_Workbook' failed.
    Is there a way to catch that?

    Thanks,
    Joe


  4. #4
    Bob Phillips
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    Yeah, as I said

    If FileExists("myfilename") Then
    'do nothing
    Else
    Activeworkbook.SaveAs Filename:="myfilename"
    End If

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Joe HM" <[email protected]> wrote in message
    news:[email protected]...
    > Hello -
    >
    > I get an error if I press either No or Cancel in the prompt that Excel
    > will show if the file already exists:
    > Run-time error '1004'
    > Method 'SaveAs' of object '_Workbook' failed.
    > Is there a way to catch that?
    >
    > Thanks,
    > Joe
    >




  5. #5
    Joe HM
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    Hello -

    I get an error if I press either No or Cancel in the prompt that Excel
    will show if the file already exists:
    Run-time error '1004'
    Method 'SaveAs' of object '_Workbook' failed.
    Is there a way to catch that?

    Thanks,
    Joe


  6. #6
    Joe HM
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    D'oh ... got you!

    I just thought that the SaveAs function would return some status.

    Thanks!
    Joe


  7. #7
    Bob Phillips
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    You can also do

    On Error Resume Next
    ActiveWorkbook.SaveAs Filename:="C:\Mytest\Volker1.xls"
    On Error GoTo 0

    which will give you the prompt that you can No/Cancel, but I prefer nthe
    first method

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Joe HM" <[email protected]> wrote in message
    news:[email protected]...
    > D'oh ... got you!
    >
    > I just thought that the SaveAs function would return some status.
    >
    > Thanks!
    > Joe
    >




  8. #8
    Joe HM
    Guest

    Re: How check for No/Cancel Button when SaveAs and file already exists?

    Great! Thanks so much!

    Joe


+ 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