Search % Replace: defined Style in template but its not used

F

Frank

Hello,

I am using a recorded makro to earch and replace for some txt which then is
formatted to H1 - when do the commands manually it works fine, when I use the
makro where multiple operations are running the H1 style is apllied but with
boarders around it.
I dd not define any borders, not in the makro, nor in the makro or replace
function.

Any Idea?
 
G

Graham Mayor

See if the following helps - this assumes H1 is a character style rather
than a paragraph style. A paragraph style will be applied to the paragraph
in whicj the word or phrase searched is contained.


Sub AddCharacterStyle()
Dim ReplaceStyle, FindText As String

FindText = InputBox("Enter text to find", _
"Find Text")

ReplaceStyle = InputBox("Enter Character Style to apply", _
"Replacement Style")

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

Selection.Find.Replacement.Style = _
ActiveDocument.Styles(ReplaceStyle)
With Selection.Find
.Text = FindText
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute replace:=wdReplaceAll
End Sub

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Frank Isernhagen via OfficeKB.com

Many Thanks

the Makro works fine but if the makro is based in a template and needs to be reused very often by several people and as there are too many headlines (60-80 in each doc) which needs to be reformatted, this is not an option.

I reposted this here with my makro (quiet small)
http://www.officekb.com/uwe/Forum.a...-Search-Replace-makro-results-in-funny-styles

The major problem is not that is not working when runing the makro.
Doing the SAME operations manually everything works fine.


PS Maybe you can also help on getting my hyperlinks working:
http://www.officekb.com/uwe/Redirect.aspx?path=/uwe/Forum.aspx/ms-word/5751

*****************************************
* A copy of the whole thread can be found at:
* http://www.officekb.com/uwe/Forum.aspx/word-docmanagement/14161
*
* Report spam or abuse by clicking the following URL:
* http://www.officekb.com/Uwe/Abuse.aspx?aid=b93f646522774624802c14a669f65cfa
*****************************************
 
G

Graham Mayor

I'm not sure I understand your problem You can make the macro available to
all by means of an add-in global template, or you could save it in the
document template. As for the borders in your result - remove the following
line from your macro.

Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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