Solved

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

Posted on 2006-10-30
3
506 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

813 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

15 Experts available now in Live!

Get 1:1 Help Now