Automatically press "No" on dialog box

hstaubyn

Board Regular
Joined
Sep 13, 2010
Messages
93
Hi,

how do you write the code to automatically click the "no" button in a dialog box?

At the moment my code executes a command, then a dialog box pops up asking me if I want to apply it to the whole document. This happens three times during the execution of my macro and I have to manually press "no" each time.

Is there a way around this?
Code:
Application.DisplayAlerts = False
doesn't work as it simply selects "Yes" in each case.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Care to share the code and what dialog box pops up?
 
Upvote 0
Hi,

thanks for the reply. I've just realised this might not be the right site as it is a code for Word...

Anyway, here it is:
Code:
Selection.Style = ActiveDocument.Styles("Normal")
    Selection.Font.Bold = False
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
 
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = ". "
        .Replacement.Text = ".  "
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " ."
        .Replacement.Text = "."
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
 
    Selection.Font.Size = 10
    Selection.Font.Name = "Arial"
 
End Sub
Every time it executes the
Code:
Selection.Find.Execute Replace:=wdReplaceAll
line, the dialog box pops up.

It says "Word has finished searching the selection. 9 replacements were made. Do you want to search the remainder of the document?" each time. The options are "Yes" or "No".
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top