Error calling WordOpenXML

D

David Thielen

On a DocumentChange event I call:

Range range = Selection.Range.Duplicate;
foreach (Shape item in range.ShapeRange) {
if (string.IsNullOrEmpty(item.AlternativeText) ||
((!item.AlternativeText.StartsWith("<wr:")) &&
(!item.AlternativeText.StartsWith("</wr:"))))
continue;
string xmlChart = item.Anchor.WordOpenXML;
....
}

The call to WordOpenXML throws the exception:
System.Runtime.InteropServices.COMException occurred
HelpLink="C:\\Program Files\\Microsoft
Office\\Office12\\1033\\WDMAIN11.CHM#25410"
Message="The object is not valid."
Source="Microsoft Word"
ErrorCode=-2146822358
StackTrace:
at Microsoft.Office.Interop.Word.Range.get_WordOpenXML()
at
AutoTag2010.net.windward.autotag.word.WordTagHandler.FindAllTags(Selection
selOn, Boolean justFirst, Int32 startSearch, Int32 endSearch) in
C:\src\version9\AutoTag\AutoTag2010\net\windward\autotag\word\WordTagHandler.cs:line
700
InnerException:

item.Anchor appears to be valid - item.AlternativeText can be read and
has the string I expect in it.

Why the error on this call? The shape is a chart.

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
C

Colbert Zhou [MSFT]

Hello Dave,

I can reproduce the issue and it looks like how it is designed because
anchor is the range where the shape is anchored so it is a mapping range
instead of the reality of chart. So the WordOpenXMl seems just not supported
for the Anchor, I think.

Best regards,
Ji Zhou
Microsoft Online Community Support
 
D

David Thielen

Hi;

Welcome back :)

This we've got to have - absoutely have to. What can we do to get the
WordOpenXML for a chart? This works sometimes BTW, just not all the
time.

thanks - dave


Hello Dave,

I can reproduce the issue and it looks like how it is designed because
anchor is the range where the shape is anchored so it is a mapping range
instead of the reality of chart. So the WordOpenXMl seems just not supported
for the Anchor, I think.

Best regards,
Ji Zhou
Microsoft Online Community Support


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
C

Colbert Zhou [MSFT]

Hello Dave,

After using the following codes to debug,

Sub Test()
Debug.Print Selection.WordOpenXML
End Sub

I find when the target selection is a shape, the WordOpenXML would be
invalid to use. Only when it is an inlineshape, the WordOpenXML would output
correctly.

So in your codes, you can first convert the shape to inlineshape by calling
Shape.ConvertToInlineShape(). After that, we can get the WordOpenXML, then we
call InlineShape.ConvertToShape() to convert it back.

http://msdn.microsoft.com/en-us/lib...rd.shape.converttoinlineshape(office.11).aspx

http://msdn.microsoft.com/de-de/lib...rd.inlineshape.converttoshape(office.11).aspx


Best regards,
Ji Zhou - MSFT
Microsoft Online Community Support
 
D

David Thielen

Ow - that is a hack. But it works and that's what matters. Ok will do.

thanks - dave


Hello Dave,

After using the following codes to debug,

Sub Test()
Debug.Print Selection.WordOpenXML
End Sub

I find when the target selection is a shape, the WordOpenXML would be
invalid to use. Only when it is an inlineshape, the WordOpenXML would output
correctly.

So in your codes, you can first convert the shape to inlineshape by calling
Shape.ConvertToInlineShape(). After that, we can get the WordOpenXML, then we
call InlineShape.ConvertToShape() to convert it back.

http://msdn.microsoft.com/en-us/lib...rd.shape.converttoinlineshape(office.11).aspx

http://msdn.microsoft.com/de-de/lib...rd.inlineshape.converttoshape(office.11).aspx


Best regards,
Ji Zhou - MSFT
Microsoft Online Community Support


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

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