VBA Code to Select "Yes" in Yes/No dialog box

Anonymous
2016-07-25T12:51:22+00:00

Hello

I have below VBA code:

  Dim Text As String

  Text = "D:\Folder\Text"

  ActiveSheet.SaveAs Filename:=Text, FileFormat:=xlTextMSDOS

  End Sub

Above Macro is stopped because "text" already exists in D:\folder as per dialog box: (do you want to replace).

what is the code should I incorporate in above code to select "yes" automatically ?

Thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2016-07-25T13:34:56+00:00

    Two choices:

    1.  Prevent the dialog from showing:

    Application.DisplayAlerts = False

     ActiveSheet.SaveAs Filename:=Text, FileFormat:=xlTextMSDOS

    Application.DisplayAlerts  = True

    1. Get rid of the old file first

    Kill Text

    ActiveSheet.SaveAs Filename:=Text, FileFormat:=xlTextMSDOS

    8 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful