Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

Macro or VBA Code to Automatically Select "Yes" to Alert Questions During Macro

   I have a macro that includes many search-and-replace operations and formatting operations in a document. Unfortunately, after many of those steps in the macro, it sends alerts like ". . . do you want to continue searching at the beginning of the document," etc., so I have to manually click "Yes" about 10 times to get through the whole macro.
    How can I make it just move on through all parts of the macro either 1) without raising those alerts at all (since they are probably unnecessary), or 2) by programmatically giving it a "Yes" each time so it can just keep moving forward without user intervention?  Thanks.
0
Randall-B
Asked:
Randall-B
1 Solution
 
Sham HaqueSenior SAP CRM ConsultantCommented:
this may work for you:

Application.DisplayAlerts = wdAlertsNone

Note  If you set this property to wdAlertsNone or wdAlertsMessageBox, Word doesn't set it back to wdAlertsAll when your macro stops running. You should write your macro in such a way that it always sets the DisplayAlerts property back to wdAlertsAll when it

0
 
GrahamSkanCommented:
There is a parameter for the Find object called Wrap that can take three values: wdFindAsk, wdFindContinue, wdFindStop. It you are doing any processing on the found range, you probably need to use wdFindStop. Do the processing and redo the Find on the rest of the document.

This illustrates:

Option Explicit

Sub CollectHighlights()
    Dim rng As Range
    Dim strText As String
   
    Set rng = ActiveDocument.Range
    Do
        With rng.Find
            .Highlight = True
            .Forward = True
            .Wrap = wdFindStop
            .Format = True
            If .Execute Then
                strText = strText & rng.Text & vbCr
                rng.Collapse wdCollapseEnd
                rng.End = ActiveDocument.Range.End
            Else
                Exit Do
            End If
        End With
    Loop While True
    MsgBox strText
End Sub
0
 
Randall-BAuthor Commented:
gbshahaq:  
    I got your solution first, and it works fine. Thanks.
GrahamSkan:
    Thanks. I'm sure your solution would work, but I'm not quite sure how to fit it into my macro, which is using "replace" and various text formatting functions. Since gbshahaq's solution does what I need and seems easier to implement, he gets the points this time.  Thanks again.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now