XMLNodes in headers, footers, text boxes etc.

E

em_serg

Hi,

I'm using XMLNodes in Word documents. There is a problem if some of
them are placed in stories other then Main Text Story (i.e. in headers/
footers, text boxes etc.). Reading XMLNodes properties in this case
causes an error for just opened documents. If XMLNodes where manually
selected after document opening, reading its properties works fine. It
is illustrated by the following VBA procedure and its output (XMLNodes
are in main text, text box and header):


Sub XMLNodesProperties()
On Error GoTo ErrorHandler

Dim myStoryRange As Range
Dim node As XMLNode
Dim i As Integer

i = 1
For Each myStoryRange In ThisDocument.StoryRanges
For Each node In myStoryRange.XMLNodes
Debug.Print "Node" & i & ": " & "StoryType = " &
myStoryRange.StoryType & ", "
Debug.Print "BaseName = " & node.BaseName & vbCrLf
i = i + 1
Next
Next myStoryRange
Exit Sub
ErrorHandler:
Debug.Print "Err = " & Err.Number & ", " & "Description = " &
Err.Description & vbCrLf
Resume Next
End Sub

Output for just opened document:
Node1: StoryType = 1,
BaseName = Test

Node2: StoryType = 5,
Err = -2147467259, Description = Method 'BaseName' of object 'XMLNode'
failed

Node3: StoryType = 7,
Err = -2147467259, Description = Method 'BaseName' of object 'XMLNode'
failed


Output after selecting each XMLNode manually:
Node1: StoryType = 1,
BaseName = Test

Node2: StoryType = 5,
BaseName = Test

Node3: StoryType = 7,
BaseName = Test


Is there a way to read XMLNode properties without selecting them all?

Best regards,
Sergei Emelyanenkov
 

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