Setting com iterop boolean value in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ntlpjc
    New Member
    • Aug 2007
    • 1

    #1

    Setting com iterop boolean value in C#

    I'm busy using the Word-inerop interface to search a Word document, but get an Error when trying to search for all bold text.

    The code looks like this:
    Microsoft.Offic e.Interop.Word. ApplicationClas s vk_word_app = new Microsoft.Offic e.Interop.Word. ApplicationClas s();

    object vk_read_only = false;
    object vk_visible = true;
    object vk_false = false;
    object vk_true = true;
    object vk_dynamic = 2;
    object vk_replaceMetho de = WdReplace.wdRep laceAll;
    int vk_bold = 1;

    vk_word_app.Sel ection.Find.Cle arFormatting();
    vk_word_app.Sel ection.Find.Fon t.Bold = vk_bold;


    And it trought an exception when trying to set the Bold property for searching:
    Exception reads:
    "Object reference not set to an instance of an object."
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ntlpjc
    I'm busy using the Word-inerop interface to search a Word document, but get an Error when trying to search for all bold text.

    The code looks like this:
    Microsoft.Offic e.Interop.Word. ApplicationClas s vk_word_app = new Microsoft.Offic e.Interop.Word. ApplicationClas s();

    object vk_read_only = false;
    object vk_visible = true;
    object vk_false = false;
    object vk_true = true;
    object vk_dynamic = 2;
    object vk_replaceMetho de = WdReplace.wdRep laceAll;
    int vk_bold = 1;

    vk_word_app.Sel ection.Find.Cle arFormatting();
    vk_word_app.Sel ection.Find.Fon t.Bold = vk_bold;


    And it trought an exception when trying to set the Bold property for searching:
    Exception reads:
    "Object reference not set to an instance of an object."
    Which line is reported for the exception?

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Welcome to TSDN. Did you miss the ; after Microsoft.Offic e.Interop.Word. ApplicationClas s vk_word_app = new?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kenobewan
        Welcome to TSDN. Did you miss the ; after Microsoft.Offic e.Interop.Word. ApplicationClas s vk_word_app = new?
        The statement seems to be covering two lines

        [CODE=css] Microsoft.Offic e.Interop.Word. ApplicationClas s vk_word_app = new Microsoft.Offic e.Interop.Word. ApplicationClas s(); [/CODE]

        Perhaps they should do a
        using Microsoft.Offic e.Word; or whatever it is to make their code lines shorter and more readable.

        Comment

        Working...