Skip to content
Loading
  • Anil Jha
    +2
    1. if (Strings.Right(Strings.Trim(ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style), 6) == "NoNumb") {  
    2.     h_prefix = sGetDocVar("CTDPrefix");  
    3.     SetDocVar("TablePrefix", "Table " + h_prefix + ".");  
    4.     t_prefix = sGetDocVar("TablePrefix");  
    5.     hNumb = "-";  
    6. } else {  
    7.     h_prefix = sGetDocVar("CTDPrefix");  
    8.     SetDocVar("TablePrefix", "Table " + h_prefix + ".");  
    9.     t_prefix = sGetDocVar("TablePrefix");  
    10. }  
    +2
  • Anil Jha
    +2
    Try this code
    1. if ((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Substring((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Length - 6)) == "NoNumb")) {  
    2.     h_prefix = sGetDocVar("CTDPrefix");  
    3.     SetDocVar("TablePrefix", ("Table "   
    4.                     + (h_prefix + ".")));  
    5.     t_prefix = sGetDocVar("TablePrefix");  
    6.     hNumb = "-";  
    7. }  
    8. else {  
    9.     h_prefix = sGetDocVar("CTDPrefix");  
    10.     SetDocVar("TablePrefix", ("Table "   
    11.                     + (h_prefix + ".")));  
    12.     t_prefix = sGetDocVar("TablePrefix");  
    13. }  
     
    +2
  • Anil Jha
    +1
    Can you paste here error details that you are getting while compliling, Also paste the code that you are compiling.
    +1
  • 0
    Hi Anil,
     
    I am getting error in Strings.Right,Strings.Trim and Paragraph[hNumb].Style. Here style property not there. These three place error is coming 
    0
  • 0
    Now Error is coming in Paragraphs(hNumb).Style. Style propery is not there. Style coming error
    0
  • 0
    This is error I am getting. 
     
    Error CS1545 Property, indexer, or event 'Paragraph.Style' is not supported by the language; try directly calling accessor methods 'Paragraph.get_Style()' or 'Paragraph.set_Style(ref object)'
     
    Here is my code. 
     
    if (sGetDocVar("CTDPrefixTandF") == "3")
    {
    hNumb = doc1.Bookmarks["\\HeadingLevel"].Range.Paragraphs[1].Range.ListFormat.ListLevelNumber.ToString();
    if (hNumb == "1")
    {
    if ((doc1.Bookmarks["\\HeadingLevel"].Range.Paragraphs[int.Parse(hNumb)].Style.Trim().Substring((doc1.Bookmarks["\\HeadingLevel"].Range.Paragraphs[int.Parse(hNumb)].Style.Trim().Length - 6)) == "NoNumb"))
    {
    h_prefix = sGetDocVar("CTDPrefix");
    sGetDocVar("TablePrefix", "Table " + h_prefix + ".");
    t_prefix = sGetDocVar("TablePrefix");
    hNumb = "-";
    }
    else
    {
    h_prefix = sGetDocVar("CTDPrefix");
    sGetDocVar("TablePrefix", "Table " + h_prefix + ".");
    t_prefix = sGetDocVar("TablePrefix");
    }
    }
    else
    {
    h_prefix = sGetDocVar("CTDPrefix");
    sGetDocVar("TablePrefix", "Table " + h_prefix + ".");
    t_prefix = sGetDocVar("TablePrefix");
    }
    } 
    0
  • Abhilash J A
    0
    Hello,
     
    try like this 
    1. var style = ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs[hNumb].Style;  
    2. var styleString = style.ToString().Trim();  
    3. if (styleString.Length >= 6 && styleString.Substring(style.Length - 6) == "NoNumb")   
    4. {  
    5.     //rest of your code 
     
    Or,
    1. string bookMark = ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.ToString();  
    2. if (bookMark.Trim() == "NoNumb") {    
    3.     h_prefix = sGetDocVar("CTDPrefix");    
    4.     SetDocVar("TablePrefix", "Table " + h_prefix + ".");    
    5.     t_prefix = sGetDocVar("TablePrefix");    
    6.     hNumb = "-";    
    7. } else {    
    8.     h_prefix = sGetDocVar("CTDPrefix");    
    9.     SetDocVar("TablePrefix", "Table " + h_prefix + ".");    
    10.     t_prefix = sGetDocVar("TablePrefix");    
    11. } 
     
     
     Cheers!!!
    0
  • 0
    Yes I am getting error. like below
     
    System.__ComObject' does not contain a definition for 'Trim' 
    0
  • 0
    Yes I used your code but. Inside if condition it is not going.In Immediate window i checked its is showing value as "object"
    0
  • 0
    Hi RajKiran,
     
    It is not convering. I tried 
    0
  • Abhilash J A
    0
    Hi Chetan,
     
    I have edited my answer, try it now. And Looks like VB was automatically performing a ToString() while c# was not. Fixed code. 
     
    Cheers!!!
    0
  • 0
    Hi Mani Kandan,
     
    I will check that code.
     
    I have one more issue but this is different.
     
    I am getting issue like this "Item with specified name does not exist."
    my code
    Selection wordsec = Globals.ThisAddIn.Application.Selection;
    if (sTextSz == "10")
    {
    object Text10 = "TableText10";
    wordsec.set_Style(ref Text10);
    }
    else if (sTextSz == "9")
    {
    wordsec.set_Style("TableText9");
    }
    else
    {
    wordsec.set_Style("TableText8");
    }
    Please anyone send me the code in VSTO word
     
    0
  • 0
    In this your code
     
    var style = ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs[hNumb].Style;
    var styleString = style.ToString().Trim();
    if (styleString.Length >= 6 && styleString.Substring(style.Length - 6) == "NoNumb")
    {
     
    I am getting error in Style it is not proper property. 
    0
  • 0
    1. if ((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Substring((ActiveDocument.Bookmarks("\\HeadingLevel").Range.Paragraphs(hNumb).Style.Trim().Length - 6)) == "NoNumb")) {
    2. h_prefix = sGetDocVar("CTDPrefix");
    3. SetDocVar("TablePrefix", ("Table "
    4. + (h_prefix + ".")));
    5. t_prefix = sGetDocVar("TablePrefix");
    6. hNumb = "-";
    7. }
    8. else {
    9. h_prefix = sGetDocVar("CTDPrefix");
    10. SetDocVar("TablePrefix", ("Table "
    11. + (h_prefix + ".")));
    12. t_prefix = sGetDocVar("TablePrefix");
    13. }
    0
  • Manikandan Murugesan
    0
    Automatic conversion isn't possible at the moment, but doing it manually will also help improve your C# skills. There's a Top 10 article here that takes you through the common differences
     Refer thr following links : https://msdn.microsoft.com/en-us/library/ms228286.aspx
    https://msdn.microsoft.com/en-us/library/aezdt881.aspx 
    https://msdn.microsoft.com/en-us/library/aa164018(office.10).aspx 
    0
  • Rajkiran Swain
    -1
    You can use http://converter.telerik.com/ site for converting your code .
    -1