Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > The quickest way to extract text with specific style from Word
 

The quickest way to extract text with specific style from Word

What is the quickest way to extract text with specific style from Word?
Currently I'm using

int count = (int)AddIn.Application.ActiveDocument.Paragraphs.Count;

for (int i = 1; i <= count; i++)
{
     Paragraph paragraph = (Paragraph)AddIn.Application.ActiveDocument.Paragraphs[i];<br />     string style = ((Style)paragraph.get_Style()).NameLocal;<br />if (String.Compare(style, Styles.Id) == 0){}
}

It is VERY slow.(
 

Boris Nikitin  Thursday, October 15, 2009 8:34 AM
Hi Boris

Based only on your question, without knowing any other information about the task, I'd say use the Range.Find.Execute method.

Word's "Find" functionality is able to find formatting, not just text. I recommend first experimenting in the Word UI (Ctrl+F, be sure to click the "More" button) to get a feel for how it works. Once you find the command combination that gives the result you want, record a macro to get the parameter values for the Execute method.

You'll find quite a few code samples for using Find in the forum, and in the Internet.
Cindy Meister, VSTO/Word MVP
Cindy Meister  Thursday, October 15, 2009 4:15 PM
Hi Boris

Based only on your question, without knowing any other information about the task, I'd say use the Range.Find.Execute method.

Word's "Find" functionality is able to find formatting, not just text. I recommend first experimenting in the Word UI (Ctrl+F, be sure to click the "More" button) to get a feel for how it works. Once you find the command combination that gives the result you want, record a macro to get the parameter values for the Execute method.

You'll find quite a few code samples for using Find in the forum, and in the Internet.
Cindy Meister, VSTO/Word MVP
Cindy Meister  Thursday, October 15, 2009 4:15 PM

You can use google to search for other answers

Custom Search

More Threads

• SQL DBA Needs help with Word Document Creation, using VSTO
• Need Help Declaring Array(s) for Workbooks.OpenText(Fieldinfo)
• Get all objects in a Word.Document in order
• Fast loading Word information
• Outlook integration using redemption - crashing
• Disable Move or Copy Sheet.
• Error opening an excel file with cached data
• Help - releasing WinWord instance at end of process.
• Issues on Integration of CRM with Outlook
• Which version of excel to launch?