Solved

macro help needed - how to auto answer dialogs

Posted on 2011-03-02
1
346 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
My experience with Windows 10 over a one year period and suggestions for smooth operation
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

803 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