3
votes

The HTML document, available here, appears to break VBA - it will crash Word 2003 and Word 2010 appears to be behaving weird.

If you open the HTML document in Word, ALT+F11 in to the VBA editor, add a class and paste this code:

Sub Test()
    Dim obj As Document
    Set obj = Application.ActiveDocument

    MsgBox (obj.Shapes.Count)

    For Each a In obj.Shapes
        MsgBox (a) 'THIS NEVER GETS HIT - w00t
    Next

End Sub

Add a breakpoint on the second message box - it wont get hit.

This deosnt make sense. Bug in Word? Corrupt HTML?

1
I tried in my Word 2010 but I also can't get into the loop. I also tried copying the contents to a normal word document, same story. Another thing: obj.shapes.selectall gives an 'out of memory' error. Can't help you further I'm afraid. - Yoh
I can't load your HTML to my Word (2013)... anyway, try to add your code to Module, not to Class. Next, try to loop through InlineShapes in this way: For Each a in obj.InlineShapes. - Kazimierz Jawor
I believe the html file is not compatible with Word, looking at the html source code, the details about the shapes are too little (or its only specific to some programs). Especially path="m@4@5l@4@11@9@11@9@5xe". Can you confirm where this html file is generated? - PatricK
The Shape-objects in the Shapes collection do not seem to be valid. If you try to access the individual objects (e.g. Debug.Print(obj.Shapes(1).Name)) you get invalid procedure call or argument, but when you try an index value that doesn't exist, like obj.Shapes(9).Name you get index into the specified collection is out of bounds. - Olle Sjögren

1 Answers

0
votes

Thanks PatricK

It looks like the path property of the shape elements has become corrupt. We need to take a closer look at the original message and its origins.

The path in the 'original' MSG file:

path="m@4@5l@4@11@9@11@9@5xe"

once muted (to path="") the issue is resolved.

http://msdn.microsoft.com/en-us/library/bb263871%28v=vs.85%29.aspx

I think the path's commas are being converted to at (@) signs at some point, as it would be valid if we replaced them, looking at the path spec in the link above.