Solved

macro help needed - how to auto answer dialogs

Posted on 2011-03-02
1
319 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
Comment Utility
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

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

Suggested Solutions

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.
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.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

772 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

11 Experts available now in Live!

Get 1:1 Help Now