|
-
Mar 21st, 2006, 05:53 AM
#1
Thread Starter
Junior Member
Word Styles
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:
Code:
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?
-
Mar 21st, 2006, 11:44 PM
#2
Thread Starter
Junior Member
Re: Word Styles
i've got part of it to work
Code:
s = new_styles("H3", "<sect3 id=""cxx-sec3-xxxx"">", "<title>")
s = new_styles("H2", "<sect3 id=""cxx-sec2-xxxx"">", "<title>")
s = new_styles("H1", "<sect3 id=""cxx-sec1-xxxx"">", "<title>")
End Sub
Function new_styles(style_name As String, style_tag As String, cont_tag As String)
' Function To Replace Style Names With Relevant XML Tags
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(style_name)
Selection.Find.Execute
With Selection.Find
.Text = ""
.Replacement.Text = style_tag & Selection.Text & cont_tag
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End Function
But when it replaces its not inserting the tag around the test for example
if the test "Sub Heading 1" is with style h1 then when the replacement takes place its done like this
<sect3 id="cxx-sec3-xxxx"><title>
but i want the output to be like this
<sect3 id="cxx-sec3-xxxx">Sub Heading 1<title>
can someone help me out here
-
Mar 27th, 2006, 04:19 AM
#3
Thread Starter
Junior Member
Re: Word Styles
BUMP:
suggestions anyone??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|