Solved

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

Posted on 2006-10-30
3
493 Views
Last Modified: 2012-06-21
   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
Comment
Question by:Randall-B
3 Comments
 
LVL 18

Accepted Solution

by:
Sham Haque earned 500 total points
ID: 17833965
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17834066
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
 

Author Comment

by:Randall-B
ID: 17834137
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now