Find out if an item exists in the Microsoft.Office.Interop.Word.Styles collection.

I am trying to access an element in a collection of styles of a dictionary document, I was wondering if there is a way to find out if an element with a given key exists without throwing an exception.

Now I am doing something like:

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

This works when an element exists, if it does not work (I know that I can use the try / catch block, but I would prefer not to.

thanks for the help

+3
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/1729631/


All Articles