Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

757 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

20 Experts available now in Live!

Get 1:1 Help Now