none
how to highlight above & after text in table using vsto in word document RRS feed

  • Question


  • Hi,

    can you please help me.......

    I am very new to VSTO but good at .NET 2013. I would like to know - in VSTO for MS Word, 

    How can i highlight above & after text of a table in word document. 

    I want to check ony by one text above & after in table through next button when click on button they move to next missing text ....that get missing specific default text which is present on above & on after table ,

    if any tag missing then highlight current table on the same 

    default value(like [[abc]])

    test1

    test2

    test4

    test3

    default value(like [[pqr]])


    test5

    test6

    test8

    test7

    default value(like [[pqr]])

    default value(like [[abc]])

    test5

    test6

    test8

    test7

    In form1.cs

    when click on next button move to next missing text and highlight table

    I want to first check missing text and then highlight table of missing text

    please please help me 



    Thursday, October 29, 2015 7:54 AM

All replies

  • Hi Sona,

    What do you mean with “above & after” and “table of missing text”? Based on your description, it seems you want to find a string and highlight the string, if so, I suggest you use Range.Find.

    Here is a simple code:

            private void button1_Click(object sender, EventArgs e)
            {
                Range range = Globals.ThisAddIn.Application.ActiveDocument.Content;
                object findText = "Test"; //string you want to find
                object oTrue = true;
                object oFalse = false;
                object oFindStop = Microsoft.Office.Interop.Word.WdFindWrap.wdFindStop;
                if (range.Find.Execute(ref findText, ref oTrue, ref oFalse, ref oTrue,
                     ref oFalse, ref oFalse, ref oTrue, ref oFindStop, ref oFalse))
                {
                    range.Select();
                    Globals.ThisAddIn.Application.Selection.Range.HighlightColorIndex = WdColorIndex.wdDarkYellow; //highlight the string which was found
                }
            }

    You could refer the link below for more information about Range.Find.

    # How to: Programmatically Set Search Options in Word
    https://msdn.microsoft.com/en-us/library/tf2wdd02.aspx?f=255&MSPPError=-2147217396

    Best Regards,

    Edward


    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.


    Friday, October 30, 2015 6:18 AM
  • Sir,

    I want check specific word i.e. [[abc]] & [[pqr]].it is always present before table & after table respectively.

    default value(like [[abc]])

    test1

    test2

    test4

    test3

    default value(like [[pqr]])

    if some times [[abc]] or  [[pqr]] missing then highlighted table

    -[[abc]]  missing hilighted table current table

    -[[pqr]]  missing hilighted table current table


    Example.

    1)

    [[ts]]

    Table 1

    test2

    test4

    test3

    [[et]]


    Table 2

    test7

    test6

    test8

    [[et]]

    [[ts]]

    Table 3

    test11

    test10

    test12


    NOTE: We have to check the tagging as well along with count match in such a way so that opening tag must be match with closing tag

    opening tag: [[ts]]

    closing tag: [[et]]

    here,I want to highlighted table 2 & table 3 because In table 2,[[ts]] is missing in before table & In table 3 ,[[et]] is missing after table.

    but one more when click on button i.e. Next then highlighted table 2 again press on button next highlighted next table that is table 3 so on

    It means highlighting one by one table through button"Next"

    Please sir i really need a help.Please provide me exact solution for the same

    Thanks.

    Tuesday, November 3, 2015 5:45 AM
  • Hi Sona,

    For your requirement, you could do as below:

    1. With the button “Previous” and “Next”, you could select the table
    2. Check the above and down line whether it meets your requirement.

    Here is a simple code to get the above & down line.

    Sub getTable()
        Dim doc As Document
        Dim t As table
        Set doc = ActiveDocument
        Set t = doc.Tables(1)
        t.Select
        Selection.MoveUp
        Debug.Print Selection.Text
        Selection.MoveLeft
        Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
        Selection.MoveRight
        Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    End Sub

    For C# code, you need to convert it to C# object, you could refer the link below for more information about Selection object.

    # Selection.Move method
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.selection.move.aspx

    Best Regards,

    Edward


    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 3, 2015 6:36 AM
  • Hi Sir ,

    Its a VBA Format....i want in vsto C# not in VBA...And How to highlighted current table 

    Please provide me solution in vsto C#for Word Document


    Tuesday, November 3, 2015 6:40 AM
  • Please give me answer
    Tuesday, November 3, 2015 9:25 AM
  • Hi Sona,

    I have shared steps to achieve your requirement, did you have issue with the specific step or which code did not work? For a C# code, you could refer the above link which shared how to use Selection.Move. Here is a simple code:

            private void SelectionMove_Click(object sender, RibbonControlEventArgs e)
            {
                Selection s = Globals.ThisAddIn.Application.Selection;
                Table t = Globals.ThisAddIn.Application.ActiveDocument.Tables[1];
                t.Select();
                s.MoveUp();
                MessageBox.Show(s.Text);
                s.MoveLeft();
                s.MoveDown(Unit:WdUnits.wdLine,Count:1,Extend:WdMovementType.wdExtend);
                MessageBox.Show(s.Text);
                s.MoveRight();
                s.MoveDown(Unit: WdUnits.wdLine, Count: 1, Extend: WdMovementType.wdExtend);
                MessageBox.Show(s.Text);
            }

    Best Regards,

    Edward


    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.



    Thursday, November 5, 2015 1:29 AM
  • Hi,

    Thank you! I found how to do it

    Friday, December 18, 2015 3:56 AM
  • Hi Soniya,

    I am glad your issue has been resolved.

    It would be appreciated if you could share us your solution, and you could mark it as answer.

    Best Regards,

    Edward


    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.


    Monday, December 28, 2015 2:14 AM