Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:08:46+00:00 2026-05-27T20:08:46+00:00

Im looking for a way to insert an MS Word Shape at cursor position.

  • 0

Im looking for a way to insert an MS Word Shape at cursor position. At the moment I have the following code which inserts a shape at a predetermined location:

        Microsoft.Office.Interop.Word.Range CurrRange = Globals.ThisAddIn.Application.Selection.Range;

        //Get the id of the MS Word shape to be inserted
        int shapeId = (int)MsoAutoShapeType.msoShapeRoundedRectangle;
        //Get the value of the name attribute from the selected tree view item
        string nodeText = treeViewItem.GetAttribute("name");

        //Add a new shape to the MS Word designer and set shape properties
        var shape = CurrRange.Document.Shapes.AddShape(shapeId, 170, 200, 100, 20);
        shape.AlternativeText = String.Format("Alt {0}", nodeText);
        shape.TextFrame.ContainingRange.Text = nodeText;
        shape.TextFrame.ContainingRange.Font.Size = 8;

The location where the shape gets inserted is hardcoded:

This can be seen from the 2nd and 3rd parameters of the AddShape() method:

170 = position measured in points to the left edge of the autoshape

200 = position measured in points to the top edge of the autoshape

I’ve had a look at the properties and methods of my Range object but cannot seem to find any which store the position values which I require.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:08:47+00:00Added an answer on May 27, 2026 at 8:08 pm

    The final parameter to AddShape is an Anchor, which expects a range object. Try passing your range into that:

    var shape = CurrRange.Document.Shapes.AddShape(shapeId, 0, 0, 100, 20,CurrRange);
    

    Update: It looks like there is a bug in Word 2010 documents that it doesn’t respect the Anchor. Save the document as a .doc file and test again, it does anchor it to the beginning of the paragraph if you do that. The link above is just to the microsoft forums, I could not find the connect bug report for the issue.

    A workaround would be to specify the top and left based on the location of the selection:

    Microsoft.Office.Interop.Word.Range CurrRange = Globals.ThisAddIn.Application.Selection.Range;
    
    //Get the id of the MS Word shape to be inserted
    int shapeId = (int)MsoAutoShapeType.msoShapeRoundedRectangle;
    
    //Get the value of the name attribute from the selected tree view item
    string nodeText = "Hello World";
    
    var left = Globals.ThisAddIn.Application.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage);
    var top = Globals.ThisAddIn.Application.Selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage);
    
    //Add a new shape to the MS Word designer and set shape properties
    var shape = CurrRange.Document.Shapes.AddShape(shapeId, left, top, 100, 20);
    shape.AlternativeText = String.Format("Alt {0}", nodeText);
    shape.TextFrame.ContainingRange.Text = nodeText;
    shape.TextFrame.ContainingRange.Font.Size = 8;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way to insert javascript code block to end of
I'm looking for the way to insert a line of code with a keystroke
I am looking for a way i can use code snippets but safely insert
Looking for a way to programmatically insert comments (using the comments feature in Word)
I have been searching for a way to insert linebreaks in my code for
I am looking for a way to insert code comment blocks semi-automatically in all
I'm looking for a way to insert a <style> tag into an HTML page
I am looking the fastest way to insert many records at once (+1000) to
I'm hand-maintaining an HTML document, and I'm looking for a way to automatically insert
I'm looking for a way to map a simple insert stored procedure using NHibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.