I am using Visual C++ to automate Word, in the following code I try to insert text followed by a picture:
// OLEParagraphs is an object of COLEParagraphs
COLEParagraph LastParagraph = OLEParagraphs.get_Last();
COLERange LastParagraphRange = LastParagraph.get_Range();
COLEInlineShapes InlineShapes = LastParagraph.get_InlineShapes();
LastParagraphRange.put_Text(_T(“See picture below:”));
InlineShapes.AddPicture(strPicFileName, COleVariant(0l), COleVariant(1l), DOCX_VARIANT_OPTIONAL);
However, after executing the code, I find the text is always put AFTER the picture, not BEFORE the picture, why?
Thanks
Given the description of the range parameter (the last for which you provide DOCX_VARIANT_OPTIONAL):
Optional Object. The location where the picture will be placed in the text. If the range isn't collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically.
I would guess this is something to do with "automatic placement". Try inserting a placeholder range before the text and specifying that as the location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With