RE: Apply formatting to XML Tag by Alicia
Alicia
Thu Sep 22 01:46:02 CDT 2005
I have used the following VBA code in word 2003 , to try to assign
userdefined styles to each tag.
Private Sub Document_XMLAfterInsert(ByVal NewXMLNode As XMLNode, ByVal
InUndoRedo As Boolean)
If NewXMLNode.BaseName = "Title" Then
NewXMLNode.Range.Style = ActiveDocument.Styles("StyleTitle")
End If
If NewXMLNode.BaseName = "Subtitle" Then
NewXMLNode.Range.Style = ActiveDocument.Styles("StyleSubtitle")
End If
End Sub
Using this approach, a particular style is selected when i insert a tag. it
works if I tag some text as Title and then tag some other text as SubTitle.
But if i insert a Title tag ,then a Subtitle Tag, and then proceed to enter
the text in those two tags, the formatting of the title tag is that of the
subtitle tag.( The code does not set the style for a particular tag's range
as i thought it would). Moreover, if i enter text in any other tag for which
the style is not defined, the style is the same as the last programmatically
applied style.
This is my first attempt at VBA.I dont know if i've missed anything.
I was also wondering whether it is possible to have a macro which sets the
style each time i click inside an xml tag od whether it is possible to do
that through code.
Could anyone help me with this please?
Any help will be greatly appreciated.
Desperately
Alicia