imatrox05
Mar 21st, 2006, 04:53 AM
I have a word document that has styles applied to it.
I am basically trying to find specific styles and add tags to it
eg:
Is a particular section
Subheading 1 has the style "H1" i want to add the tags
<heading1> to it so that it looks like this
<heading1>Subheading 1</heading1>
Here's the code that i am using:
Sub style_search()
s = my_style("CN", "<UnitTitle language=""EN"" unitlabel=""X"">", "<CT>")
s = my_style("H1", "<sect1 id=""cxx-sec1-xxxx>""", "<title>")
s = my_style("H2", "<sect2 id=""cxx-sec2-xxxx>""", "<title>")
s = my_style("H3", "<sect3 id=""cxx-sec3-xxxx>""", "<title>")
End Sub
Function my_style(style_name As String, start_tag As String, conc_tag As String)
Selection.Find.ClearFormatting
'Selection.Find.Style = ActiveDocument.Styles(style_name)
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Style = ActiveDocument.Styles(style_name)
.Replacement.Text = "<sect3 id=""cxx-sec3-xxxx>" & Selection.Text & "<title>"
.Replacement.Font.Color = wdColorBrightGreen
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Function
but this does not seem to work. Any ideas why?
I am basically trying to find specific styles and add tags to it
eg:
Is a particular section
Subheading 1 has the style "H1" i want to add the tags
<heading1> to it so that it looks like this
<heading1>Subheading 1</heading1>
Here's the code that i am using:
Sub style_search()
s = my_style("CN", "<UnitTitle language=""EN"" unitlabel=""X"">", "<CT>")
s = my_style("H1", "<sect1 id=""cxx-sec1-xxxx>""", "<title>")
s = my_style("H2", "<sect2 id=""cxx-sec2-xxxx>""", "<title>")
s = my_style("H3", "<sect3 id=""cxx-sec3-xxxx>""", "<title>")
End Sub
Function my_style(style_name As String, start_tag As String, conc_tag As String)
Selection.Find.ClearFormatting
'Selection.Find.Style = ActiveDocument.Styles(style_name)
Selection.Find.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Style = ActiveDocument.Styles(style_name)
.Replacement.Text = "<sect3 id=""cxx-sec3-xxxx>" & Selection.Text & "<title>"
.Replacement.Font.Color = wdColorBrightGreen
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Function
but this does not seem to work. Any ideas why?