Macro to look for 2 diffrent text selections occurences in the document ad replace them with another text.
hi,
i need write macro either "text1" or "text2" occurnaces in document , replace them "text3"
here doing 1 of them.
with selection.find .text = "text1" .replacement.text = "text3" .forward = true .wrap = wdfindcontinue .format = false .matchcase = true .matchwholeword = false .matchwildcards = false .matchsoundslike = false .matchallwordforms = false end selection.find.execute selection if .find.found = false msgbox "text1 not updated." else .collapse direction:=wdcollapsestart .find.execute replace:=wdreplaceone .find.execute end if end
but in documents either "text1" occurs or "text2". don't know how write code search both text1 , text2.
thank you
sub scratchmacro()
'a quick macro scratch pad created greg maxey
dim searcharray() string
dim myrange range
dim long
dim termstring string
searcharray = split("text1|text2", "|")
set myrange = activedocument.range
= 0 ubound(searcharray)
termstring = searcharray(i)
myrange.find
.text = termstring
.replacement.text = "text3"
.matchwholeword = true
.execute replace:=wdreplaceall
end with
next
end sub
"far asg" wrote in message news:56389c44-f474-4a15-89e1-3d6534b12cb9@communitybridge.codeplex.com...
hi,
i need write macro either "text1" or "text2" occurnaces in document , replace them "text3"
here doing 1 of them.
with selection.find .text = "text1" .replacement.text = "text3" .forward = true .wrap = wdfindcontinue .format = false .matchcase = true .matchwholeword = false .matchwildcards = false .matchsoundslike = false .matchallwordforms = false end selection.find.execute selection if .find.found = false msgbox "text1 not updated." else .collapse direction:=wdcollapsestart .find.execute replace:=wdreplaceone .find.execute end if end with
but in documents either "text1" occurs or "text2". don't know how write code search both text1 , text2.
thank you
greg maxey please visit website at: http://gregmaxey.mvps.org/word_tips.htm
Microsoft Office > Word IT Pro Discussions
Comments
Post a Comment