none
How to find style count of particular style in VSTO word. RRS feed

  • Question

  • Hi All,

    How to find style count of particular style in VSTO word. 

    Thanks in Advance!!!!

    Monday, November 23, 2015 11:04 AM

Answers

  • Hi vikas,

    If you want to statistics styles count, you could use Document.Styles property.

    If you want to statistics the particular style in current document, you could use Selection.Find property with particular style to achieve that.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 24, 2015 6:58 AM
    Moderator
  • Hi Vikas

    It's usually not too difficult to "translate" the VBA. VSTO code is the same object model. But if you run into difficulties going from VB-speak to C# post the maco recorder code and your attempt to bring it into C#, telling us where it's failed and we can help you.

    The reason you need to do this is that we can't know what actually worked for you in the UI, so we can't give you the "right" code without this information. That's why I asked you to record the macro...


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Tuesday, December 1, 2015 2:49 PM
    Moderator

All replies

  • Please provide more information - it's not clear what you want.

    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Monday, November 23, 2015 4:44 PM
    Moderator
  • Hi vikas,

    If you want to statistics styles count, you could use Document.Styles property.

    If you want to statistics the particular style in current document, you could use Selection.Find property with particular style to achieve that.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 24, 2015 6:58 AM
    Moderator
  • Hi Cindy and Starain,

    Thanks for reply..

    I am working on one functionality in C# VSTO where i have to highlight the instances of a particular style. Lets say, i have a style named "my-style1", so i would like to select the available "my-style1" styles throughout the word document.

    Eg:- 

    This is para 1

    This is para 2

    This is para 3

    In Above content, ONLY "This is para1" is applied with "my-style1" . I want a code to select/highlight only "This is para1" sentence.

    Thanks in Advance!!!


    Wednesday, November 25, 2015 9:50 AM
  • Hi Vikas

    Starain's second suggestion is the one for you to investigate in more detail, then :-)

    Start by testing in Word as a user. Ctrl+F will activate Find functionality. If this opens a pane on the left on your machine, click the arrow next to the dropdown and select "Advanced Find" to get the dialog box.

    In the dialog box, click "More", then "Format" and choose "Style". Select the style name, then OK back to the main dialog box. Make sure there's nothing in the "Find what" box (no text to search) - the only search condition should be the style. From "Reading Highlight" choose "Highlight all".

    If this is the result you need, record a macro and repeat the steps. This will give you the basic syntax to use in your C# code.


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Wednesday, November 25, 2015 4:10 PM
    Moderator
  • Hi Cindy,

    I tried this but this is a macro code. I want VSTO code for the same.

    Thanks,

    Vikas

    Tuesday, December 1, 2015 5:17 AM
  • Hi Vikas,

    They are similar.

    A simple sample to find the text (document-level add-in).

    public void SelectionFind(string t)
            {
                object findText = t;
    
                Application.Selection.Find.ClearFormatting();
    
                if (Application.Selection.Find.Execute(ref findText,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing))
                {
                    MessageBox.Show("Text found.");
                }
                else
                {
                    MessageBox.Show("The text could not be located.");
                }
            }

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 1, 2015 8:50 AM
    Moderator
  • Hi Vikas

    It's usually not too difficult to "translate" the VBA. VSTO code is the same object model. But if you run into difficulties going from VB-speak to C# post the maco recorder code and your attempt to bring it into C#, telling us where it's failed and we can help you.

    The reason you need to do this is that we can't know what actually worked for you in the UI, so we can't give you the "right" code without this information. That's why I asked you to record the macro...


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Tuesday, December 1, 2015 2:49 PM
    Moderator