Solved

macro help needed - how to auto answer dialogs

Posted on 2011-03-02
1
336 Views
Last Modified: 2012-08-13
I have a macro in MS Word (2007) that loops through all the content making some formatting changes, and then replaces two line breaks with one line break. This last part has to be accomplished 3 times so that all extraneous, empty lines are removed from the page. The macro works, but that last part the user is forced to answer the modal dialog: "Word has finished searching the selection. # replacements were made. Do you want to search the remainder of the document?" with Y/N buttons. I need this question programmatically answered in a fashion that allows the macro to continue through, and then at the very end, I want a modal dialog that says 'Formatting Complete' with an 'OK' button.

Any ideas how to help finish this off?


The code here shows where the dialog is being forced.

(i didn't include the first section as it it's not at issue here..)
..
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^l^l"
        .Replacement.Text = "^l"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Open in new window



Thank you!

Keith
0
Comment
Question by:UPI-ITM
1 Comment
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 35019376
Try using the document range instead of the Selection.

Sub RangeFinder()
    With ActiveDocument.Range.Find
            .Text = "^l^l"
            .Replacement.Text = "^l"
            .Execute Replace:=wdReplaceAll
             .Execute Replace:=wdReplaceAll
            .Execute Replace:=wdReplaceAll
   End With
End Sub
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Outlook Free & Paid Tools
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

862 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

24 Experts available now in Live!

Get 1:1 Help Now