• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 796
  • Last Modified:

Word HeadingStyle.Style produces Type Mismatch error

Hi,

I have developed a VSTO add-in for Word 2007 & 2010 using Visual Studio 2010. The following line of code checks whether a table of contents references a specified style at a specified level in its field code:

Dim stylePresent as Boolean = (From heading As Word.HeadingStyle
                                                    In referenceTOC.HeadingStyles
                                                    Where heading.Level = level _
                                                    And heading.Style = styleName).Any

 - referenceTOC is decalred as a Microsoft.Office.Interop.Word.TableOfContents
 - level is an integer
 - styleName is a string

This works in Word 2010 but fails in Word 2007 with a COM exception - the message says Type Mismatch. It seems that any code I tried that references the Style property of a HeadingStyle object produces a Type Mismatch error. I tried a For-Next loop instead of using LINQ but got the same issue.

Any ideas?

Pete
Xenacode Ltd
0
xenacode
Asked:
xenacode
  • 3
  • 3
1 Solution
 
CodeCruiserCommented:
If you do not include Style in your query, does it return any results? If it does, what does Style property return as its type?
0
 
xenacodeAuthor Commented:
It does return results. Just referencing the Style property causes an error, even when debugging in Visual Studio using immediate  window
0
 
CodeCruiserCommented:
Which version of PIAs are you using?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
xenacodeAuthor Commented:
2010 embedded
0
 
CodeCruiserCommented:
The chances are that the type of that property has changed between the two office versions.
0
 
xenacodeAuthor Commented:
I guess that's one of the drawbacks of using embedded interops. I figured this out and got round the problem by using late binding i.e. took out the "As Word.HeadingStyle" bit from the LINQ query.

Thanks for setting me on the right track there.

Pete
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now