Solved

macro help needed - how to auto answer dialogs

Posted on 2011-03-02
1
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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 …

732 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