views:

27

answers:

1

Hi

I'm trying to access an item on the Styles collection of a word document, I was wondering if there's a way to know if an item with a given key exists without it throwing an exception.

Right now I'm doing something like:

newStyle = _document.Styles.get_Item(ref styleName);

This works when the item exists, if it doesn't it will fail (I know that I can use a try/catch block but I would prefer not to.

Thanks for your help

+1  A: 

You need to loop over the styles and check the name, and exit the loop if you have a match.

Mikael Svenson