search and replace need assistance

J

jgc

hello
I am a novice so please bear with me...in a nutshell i am trying to auto
launch the search/replace dialog box in Word with the find text already
filled in. I think i am close but when i click replace all (without filling
in the replace with text box) and then close i receive runtime error 5524.
Any help would be greatly appreciated. I have included the code which may or
may not be helpful.
thanks in advance.

Sub autoopen()
MsgBox "When prompted please type the application name into the find/replace
window"
Call jenmacrolaunch
End Sub
Sub jenmacrolaunch()
'
' Macro1 Macro
' Macro recorded 4/5/2007 by Jennifer
'
Dialogs(wdDialogEditReplace).Show
Call jenmacro
End Sub
Sub jenmacro()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "appname"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
D

Doug Robbins - Word MVP

Probably better if you tell us exactly what you are wanting to do rather
than, or at least in addition to, how you have tried to go about it. There
is probably a better way. For example if you want to ask the user for some
text to be deleted from the document (i.e. be replaced with nothing) then
use:

Dim mystr As String
mystr = InputBox("Enter the text that you want to delete from the
document.")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:=mystr, ReplaceWIth:="",
MatchWildcards:=False, Forward:=True, Wrap:=wdFindStop) = True
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

jgc

my apologies for not being clear.
I have an existing doc that is filled out by several different users. In
this doc the user currently types over %appname% with the name of their
application several times.

This is what I need to do: When the existing word doc opens the user should
get prompted with a box where they can type. When they click on ok for
example (if using an input box) or replace (if using the
wrddialogeditreplace) the name they typed would replace %appname% throughout
the document.
If they do not type in anything they should get prompted with a message to
please input the text and the original box where they can type the appname
re-appears.

thanks in advance.
 
D

Doug Robbins - Word MVP

In that case use:

Dim mystr As String
mystr = InputBox("Enter the name of the application.")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="%appname%", ReplaceWith:=mystr,
MatchWildcards:=False, Forward:=True, Wrap:=wdFindStop) = True
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

This sounds like a bit of wheel reinvention to me. A simple ASK field (or a
userform) to collect the input and a raft of REF fields (in place of
%appname%) to place it would seem a better option?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

jgc

Thank you Graham. I figured I was overcomplicating this. Unfortunately,
there is no error control with the solution Doug provided which is where I
was stuck. I am looking into how to use the ask and ref fields and will let
you know. thanks again.
 

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