Mircrosoft.Interop Word

csharp Sri Lanka
  • 9 years ago

     I am trying to add a picture to my word document. Afterwords I would like to set the layout on the picture to tight instead of in line with text, although i can't figure out how to do this programmatically. Here is my code:


                Word.InlineShape map = oDoc.InlineShapes.AddPicture("C:\\Projects\\VegMgmtApp\\Data" + "\\Map.jpg", ref linktofile, ref savewithdocument, ref temprng);
                map.Height = 500;
                map.Width = 350;


    Thanks in advance.

  • 9 years ago

     Hi! Welcome to Developer Fusion :)

    Are you successfully inserting the image okay? Looking at this article: http://www.microsoft.com/technet/scriptcenter/resources/officetips/sept05/tips0922.mspx (in VBA) it looks like you're along the right lines... does the image definitely exist?

  • 9 years ago

    I actually figured it out over the weekend. Instead of adding the image as in InlineShape, I had to add it to the Shapes.Collection. Not sure why they make you do it that way but it works. Here is the code in case anyone has the same problem:

    //Insert Map
                Word.Shapes collection = oDoc.Shapes;
                System.Object EndofDocument = wrdRng;
                System.Object Left = 180;
                Word.Shape map = collection.AddPicture("C:\\Projects\\VegMgmtApp\\Data" + "\\Map.jpg", ref missing, ref missing, ref Left, ref missing, ref missing, ref missing, ref EndofDocument);
                map.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;



    Thanks for your help!

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray