Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
help with flyer 3 81
Java Filesystem manipulation of Word Docx file (find replace text) 3 93
Protection area in Word 2 47
Microsoft Word Add-in Start automatically 8 54
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
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 …

856 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