Hi Gareth,
Thank you for the additional information; I was able to reproduce the
problems you described and have filed bug reports on both (the reports I
submitted are pasted below). Unfortunately, I do not see a workaround;
however, if I learn of one from the bug report resolution, I will certainly
post that information here as a reply to this message.
=======================
Title: Word 11: Attribute added in XMLAfterInsert event is added to wrong
node & crashes Word
Overview of the problem:
When you use the XMLAfterInsert event to add an attribute to an XML node,
the attribute is added to the wrong node when the new node resides in a
text box or in the header/footer.
1. Start a new document (Doc1).
2. Attach the following schema to Doc1:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="
http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="
http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="
http://tempuri.org/XMLSchema.xsd"
xmlns:xs="
http://www.w3.org/2001/XMLSchema">
<xs:element name="element1">
<xs:complexType>
<xs:sequence />
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
3. Add the following code to the ThisDocument code module of Doc1:
Private Sub Document_XMLAfterInsert(ByVal NewXMLNode As XMLNode, ByVal
InUndoRedo As Boolean)
Static i As Integer
NewXMLNode.Attributes.Add("attribute1", "").NodeValue = i
i = i + 1
End Sub
4. Insert an element1 node; verify the attribute1=0.
5. Insert a second element1 node; verify the attribute1 of the first
element is still 0 and the attribute1 of the second element is 1.
6. Activate the header/footer.
7. Insert a third element1 node into the header.
Now observe that the third element1 has no attribute1 but the attributes in
the first element1 have incorrectly changed.
================
Title: Word 11: Cannot access NextSibling and PreviousSibling properties
for XMLNodes in header/footer
Overview of the problem:
Elements in header/footer and textboxes cannot be accessed via NextSibling
and PreviousSibling.
1. Start a new document (Doc1).
2. Attach a schema to Doc1. For example:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="
http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="
http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="
http://tempuri.org/XMLSchema.xsd"
xmlns:xs="
http://www.w3.org/2001/XMLSchema">
<xs:element name="element1">
<xs:complexType>
<xs:sequence />
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
3. Add this macro to Doc1:
Public Sub test()
Dim n As XMLNode
Set n = Selection.XMLNodes(1).NextSibling
If n Is Nothing Then
MsgBox "No next sibling"
Else
MsgBox n.BaseName
End If
End Sub
4. Insert two elements in the body of the document, select both elements
and run the macro test -- notice that the sibling is found.
5. Insert two elements in the header of the document, select both elements
and run the macro test -- notice that NO sibling is found.
6. Insert two elements into a text box in the document, select both
elements and run the macro test -- notice that NO sibling is found.
Regards,
Lori Turner
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------