Any way to have Dialog(wdDialogEditReplace) function like interactive Replace Dialog

T

TomT

Folks,
I want to have the Replace dialog displayed with parameters drawn from a
text file in which the lines have the format "Findstring=ReplaceString".
E.g., an entry of "1=2" would populate the find field of the dialog with "1"
and the replace field with "2". The code below more or less works except
that after the user selects "Replace All", the usual prompt indicating that
"X replacements have been made" or "Word has finished searching the
document" does not appear. Thus, it will be a bit disorienting when using
the routine. Am I missing some properties that enable/disable the messages?

Thanks,
Tom

Sub testreadfile()
Dim AStr() As String
Dim SearchStr As String
Dim RplcStr As String
Dim FString As String
Dim DlgFind As Dialog
Dim AString As String
On Error Resume Next
Set DlgFind = Dialogs(wdDialogEditReplace)
FString = "C:\wordmacros\a.txt"
Open FString For Input Access Read As #1
While Not EOF(1)
Line Input #1, AString
If Len(AString) > 0 And Not AString Like "*[=]*" Then
MsgBox AString + " is not a valid entry"
End If
AStr = Split(AString, "=")
SearchStr = Trim(AStr(0))
RplcStr = (AStr(1))
With DlgFind
.Find = SearchStr
.Replace = RplcStr
.Show
End With
Wend
Close #1
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top