locked
MS Word OLE automation in visual studio 2010 RRS feed

  • Question

  • Hi

    I'm working on small application to add images to word document using MS OLE automation, provided in wxWidgets.

    I'm successfully able to add image to active open document and also text. However I'm not able to insert my images in sequences

    they getting stacked one over another. 

    I tried various method by inserting line after first, also inserting new paragraph but none is working. Hence I've to manually

    move my cursor to next position.

    Please suggest something how can I specify the location, or how can I separate out my images.

    I'm facing this issue just for images, for text is working fine.

    Here is the snippet of my code

                wxAutomationObject wordDoc2;
                if(FAILED(CoInitialize(NULL)))
                {
                    return;
                }
     
    
                if (!wordDoc2.GetInstance("Word.Application", wxAutomationInstance_UseExistingOnly )) {
                    return;
                } 
    
                wordDoc2.PutProperty("Visible", true);
                wordDoc2.PutProperty("Options.Overtype", false);
    
                wxAutomationObject actDoc;
                wordDoc2.GetObject(actDoc, "ActiveDocument");
    
                #if 1
                wxAutomationObject selDoc;
                actDoc.GetObject(selDoc, "Selection");
        
                wxAutomationObject wordContent;
                actDoc.GetObject(wordContent,"Content");
               
                wordContent.CallMethod("InsertAfter", "\n");
                wordContent.CallMethod("InsertAfter", "This new Line");
    
                actDoc.CallMethod("Shapes.AddPicture", filename);
                actDoc.PutProperty("Shapes.Name", "Rectangle");
                actDoc.CallMethod("Shapes(\"Rectangle\").Select");
                actDoc.CallMethod("Selection.InsertParagraphAfter");
    
                actDoc.CallMethod("Save");
    
              //  wordDoc2.CallMethod("Quit");
               CoUninitialize();

    Thanks and Regards,

    Pradeep


    • Edited by praks411 Friday, November 29, 2013 10:23 AM
    • Moved by Anna Cc Monday, December 2, 2013 3:34 AM
    Thursday, November 28, 2013 5:40 PM

Answers

  • Hi praks411,

    Welcome to MSDN forum!

    I'm afraid that you did not post in the correct forum. Your issue is related with microsoft office.

    You can consider posting it in Word for Developers forum for more efficient responses. Thanks.

    • Proposed as answer by Just Karl Monday, December 2, 2013 4:23 AM
    • Marked as answer by Just Karl Monday, December 9, 2013 3:23 PM
    Monday, December 2, 2013 3:32 AM

All replies

  • Hi,

    I've been trying various options to insert line or a new paragraph after previous inserted image namely by using following methods.

    wxAutomationObject actDoc;
    wordDoc2.GetObject(actDoc, "ActiveDocument");
    actDoc.CallMethod("Selection.Content.InsertAfter", "\n");   
    actDoc.CallMethod("Selection.Content.InsertAfter", "\n");      
    actDoc.CallMethod("Selection.Content.TypeParagraph");

    Thanks

    Pradeep

    • Edited by praks411 Friday, November 29, 2013 10:28 AM formatted
    Friday, November 29, 2013 10:28 AM
  • Hi praks411,

    Welcome to MSDN forum!

    I'm afraid that you did not post in the correct forum. Your issue is related with microsoft office.

    You can consider posting it in Word for Developers forum for more efficient responses. Thanks.

    • Proposed as answer by Just Karl Monday, December 2, 2013 4:23 AM
    • Marked as answer by Just Karl Monday, December 9, 2013 3:23 PM
    Monday, December 2, 2013 3:32 AM
  • Ok Thanks I've posted my question in the forum suggested by you Word for Developers.

    I hope someone replies to it.

    Monday, December 2, 2013 5:30 PM