none
WORD AUTOMATION FOR PICTURES NOT WORKING RRS feed

  • Question

  • Hi I followed below article to do mailmerge in word.

    http://support.microsoft.com/kb/301659

    But the code is not working for Pictures.

    If my merge FIELD is like { INCLUDEPICTURE { MERGEFIELD Pic \* MERGEFORMAT }

    In my data source Pic is "D:\\Sample.jpg

     oDoc.MailMerge.OpenDataSource(dataSourcePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
    oDoc.MailMerge.Execute();
     oWord.ActiveDocument.SaveAs(savedFileName);

    The saved document does not showing picture.

     
    • Moved by CoolDadTx Thursday, November 13, 2014 2:50 PM Office related
    Thursday, November 13, 2014 1:23 PM

Answers

All replies

  • Hi I followed below article to do mailmerge in word.

    http://support.microsoft.com/kb/301659

    But the code is not working for Pictures.

    If my merge FIELD is like { INCLUDEPICTURE { MERGEFIELD Pic \* MERGEFORMAT }

    In my data source Pic is "D:\\Sample.jpg

     oDoc.MailMerge.OpenDataSource(dataSourcePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
    oDoc.MailMerge.Execute();
     oWord.ActiveDocument.SaveAs(savedFileName);

    The saved document does not showing picture.

     

    I would suggest to double check the path to your Pic, looking at D:\\Sample.jpg would cause an error, most likely because its an invalid path.

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Thursday, November 13, 2014 9:03 PM
  • When you use field coding like that, the fields in the document will need to be updated after the merge has run. That could be done with (VBA) code like:
    ActiveDocument.Fields.Update
    However, that would still leave the pictures linked to the images in D:\. After updating, you could unlink them with (VBA) code like:
    ActiveDocument.Fields.Unlink

    For some more robust field coding for mailmerge image insertion, see 'Managing Mailmerge Graphics' at:
    http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html
    or:
    http://windowssecrets.com/forums/showthread.php/163017-Word-Mailmerge-Tips-amp-Tricks

    Contrary to what danishani says, D:\\Sample.jpg would NOT cause an error (unless the pictures aren't in D:\) - the double backslashes are correct. However, if you have "D:\\Sample.jpg as the source (which is what your post describes), the " would cause an error.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, November 13, 2014 10:05 PM
  • When you use field coding like that, the fields in the document will need to be updated after the merge has run. That could be done with (VBA) code like:
    ActiveDocument.Fields.Update
    However, that would still leave the pictures linked to the images in D:\. After updating, you could unlink them with (VBA) code like:
    ActiveDocument.Fields.Unlink

    For some more robust field coding for mailmerge image insertion, see 'Managing Mailmerge Graphics' at:
    http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html
    or:
    http://windowssecrets.com/forums/showthread.php/163017-Word-Mailmerge-Tips-amp-Tricks

    Contrary to what danishani says, D:\\Sample.jpg would NOT cause an error (unless the pictures aren't in D:\) - the double backslashes are correct. However, if you have "D:\\Sample.jpg as the source (which is what your post describes), the " would cause an error.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thanks Paul, I learn something new every day :)


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Thursday, November 13, 2014 10:51 PM