InlineShape.Height throws exception "Command Failed"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Malvika Shrivastava
    New Member
    • Jun 2010
    • 10

    InlineShape.Height throws exception "Command Failed"

    Hi Everyone,

    Please go through the code below:

    InlineShape il = doc.Sentences[i].InlineShapes[1];
    float height = il.Height;

    The second line is some times working fine but at times it throws an exception "Command Failed".

    Kindly help me in this.

    Thanks,
    Malvika.
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Are you sure that il has been assigned a value every time this error occurs? If doc.Sentences[i].InlineShapes[1] has no value, it's impossible to get it's height.

    Steven

    Comment

    • Malvika Shrivastava
      New Member
      • Jun 2010
      • 10

      #3
      ya i am sure its always being assigned with a value because i first check if there is an inline shape or not.if i get an inline shape then only further processing is done.

      Thanks.
      Malvika.

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        Can you post the complete code for this class and the full error message please?

        Steven

        Comment

        • Malvika Shrivastava
          New Member
          • Jun 2010
          • 10

          #5
          for (i = 1; i <= doc.Sentences.C ount; i++)
          {
          if (doc.Sentences[i].InlineShapes.C ount > 0)
          {
          InlineShape il = doc.Sentences[i].InlineShapes[1];
          float height = il.Height;
          float var = 19.7f;
          if (height == var)
          {
          ii_ty = ii_ty + 1;
          i = bookmarkTestYou rself_New(doc, i);
          }
          }
          }

          Comment

          • MrMancunian
            Recognized Expert Contributor
            • Jul 2008
            • 569

            #6
            First, edit your post and put your code between CODE-tags (the #-sign in the bar). Second, I asked for the full error message. Please add that as well.

            Steven

            Comment

            • Malvika Shrivastava
              New Member
              • Jun 2010
              • 10

              #7
              The exception is as follows:

              {System.Runtime .InteropService s.COMException (0x800A1066): Command failed
              at Microsoft.Offic e.Interop.Word. InlineShape.get _Height()
              at BookmarkText.Fo rm1.scanWholeDo cument() in F:\BookmarkText \BookmarkText\F orm1.cs:line 220}

              Comment

              • Malvika Shrivastava
                New Member
                • Jun 2010
                • 10

                #8
                Code:
                for (i = 1; i <= doc.Sentences.Count; i++)
                {
                if (doc.Sentences[i].InlineShapes.Count > 0)
                { 
                InlineShape il = doc.Sentences[i].InlineShapes[1];
                float height = il.Height; 
                float var = 19.7f;
                if (height == var)
                {
                MessageBox.Show("Match Found");
                }
                }
                }

                Comment

                Working...