locked
Word 2010 Template File (.dotx) with Different Mail Merge Logos Using INCLUDEPICTURE RRS feed

  • Question

  • Sorry for the background, but more information usually is better than not enough.  I work for a software company and one of our features is that we take data from a form, put into mail merge word document, converts to a pdf and then sends out via email to recipient(s).  All done automatically, so the user never actually accesses the word document, it just pulls up as a converted pdf.  We have 6 possible logos that can be inserted into the converted pdf document.  I can do a simple insert link to the pic to have it pull in one logo, but it needs to be fluid based upon a merge field.  I looked all the over the web and no solution seems to help, I am hoping I am simply doing something incorrect as I am running out of hope.  So far I have the following:

    {_INCLUDEPICTURE_"{_IF_TRUE_"C:\\Image_Folder\\logos\\{MERGEFIELD_PMCo_}.jpg"_}"_/d_}

    Where _ is included above to indicate spaces that I have.

    The MERGEFIELD PMCo will pull in either 1,2,3,4,5 or 6, which I am hoping to have pull in 3.jpg into the pdf automatically.

    With the above statement inserted into my .dotx files, the mail merge results in error filename not specified.

    Thank you in advance for your help and please let me know if I can provide any more information. 


    • Edited by apclark Wednesday, January 8, 2014 1:42 AM Added error information
    Wednesday, January 8, 2014 1:11 AM

Answers

  • Well, things may get tricky at this point, depending on who wrote the code, what type of code it is, where it is and how much of it there is. If you're not familiar with the code yourself, it is likely to be hard to find and interpret. But if you want to try...


    First, if you're using a third party product then the chances are that you wouldn't be able to get at the code anyway. If it's proprietary code, perhaps written by someone else in your company, you might have to ask someone for the source code, particularly if it's .NET code (C# or VB.NET, say). If it's VBA, then roughly speaking, the code will either be in the document itself (it would be a .docm or a .doc) or in a template/addin (a .dotm usually).

    If it's a template/addin, you can have a look at the current list of Addins in Word using FIle->Options->Addins. That may give you a clue as to what type of addin you have. Also, since VBA code can be "obfuscated", you may not be able to see anything even doing the following...

    To get at any VBA code in a .docm or .dotm, you would need to
     a. enable the Developer tab in Word, if necessary, by checking the relevant box in the right-hand column in via File->Options->Customize Ribbon

     b. click the Developer Tab, then the Visual Basic icon at the left hand end

     c. Have a look down the list of projects and see if you can spot the one that is providing the functionality you describe.

     d. If it's a .dotm, I think you will need to open the .dotm using Word's normal file->open command. While it's attached/opened as a template, you can't usually get at the VBA.

    If you manage to open the correct template/document, the code is organised under that particular project, in ThisDocument, in "Forms" (possibly), "Modules" and "Class modules". You can double-click on each one to see what's in there. Whether any of it will make any sense is another matter!

     

    Peter Jamieson

    • Marked as answer by Tony Chen CHN Friday, January 24, 2014 2:56 AM
    Thursday, January 9, 2014 4:02 PM

All replies

  • What does {MERGEFIELD PMCo} return on its own? Have you confirmed that the path & (C:/Image Folder/Logos/) & file extensions (.jpg) are correct?

    FWIW, the only spaces you need are as indicated in the following representation:
    {INCLUDEPICTURE {IF TRUE "C:\\Image Folder\\Logos\\{MERGEFIELD PMCo}.jpg"} \d}

    Note: All three sets of field brace pairs (ie '{ }') for the field construction are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, January 8, 2014 4:30 AM
  • Paul - MERGEFIELD PMCo returns a number on its own, i.e. 1.  And yes I have confirmed the path and extensions are correct.  I did try removing extraneous spaces and it still fizzled out on me.  Thank you for your time.

    Wednesday, January 8, 2014 11:47 AM
  • The fact that you are seeing "!Filename not specified" at all is unusual in Word 2010, and suggests that

    • the path is actually still not correct
    • you still have "/d" rather than "\d" in your field code.

      If you had "\d", once you updated your field code, you would almost certainly see a different message saying "The linked image cannot be displayed. (and so on)"  inside a box.

      My guess is that there is still some additional space of some kind inside the result of the string

      C:\\Image Folder\\Logos\\{MERGEFIELD PMCo}.jpg

      If you merge to a new document and inspect the generated strings carefully, it may be easier to spot either that, or some other problem that isn't apparent.

      As an aside (from your description I do not thin kit has a bearing on this matter), in my view the syntax

      { INCLUDEPICTURE "{ IF TRUE "C:\\Image Folder\\logos\\{MERGEFIELD PMCo }.jpg" }" \d }

      Is the correct one to use if you want the fields to remain in the result document (if that is what you are producing. I'm not concerned with the spaces here, but if you omit the outer double quotation marks as follows

    { INCLUDEPICTURE { IF TRUE "C:\\Image Folder\\logos\\{MERGEFIELD PMCo }.jpg" } \d }

    then what you get in the output is, e.g.

    { INCLUDEPICTURE C:\\Image Folder\\logos\\1.jpg \d }

    Although Word generates the pictures correctly, if you then actually select and update the field codes, Word will not find the pictures because of the space in the path name. If you retain the "", the output contains

    { INCLUDEPICTURE "C:\\Image Folder\\logos\\1.jpg" \d }

    and updating the field works correctly (assuming the correct path etc.)





    Peter Jamieson

    • Edited by Peter Jamieson Wednesday, January 8, 2014 4:17 PM formatting
    Wednesday, January 8, 2014 2:20 PM
  • Thank you for your help Peter. 

    So I made sure I had the \d, so it looks like this:

    {INCLUDEPICTURE {IF TRUE "C:\\Image Folder\\Logos\\{MERGEFIELD PMCo}.jpg"} \d}

    You are correct that I get the "The linked image cannot be displayed..." message.  It now seems to work generating the correct logo in the header for me in the pdf and as a word generated document.  Now the issue is that it is whacking out the table merge date below in the body of the document.  Data is no longer displaying, just the merge field name, i.e. <<RFI Date>>. 

    Wednesday, January 8, 2014 6:32 PM
  • Progress of sorts, then!

    (FWIW it might have made a difference to know that the INCLUDEPICTURE was in a header :-) It could be a "back to the drawing board moment" for anyone looking at this problem. )

    > the table merge date below in the body of the document

    Is this definitely in the document body?

    > Data is no longer displaying, just the merge field name, i.e. <<RFI Date>>

    I have been wondering whether you are creating the PDF by

     - merging to a new document, then saving that as a PDF or

     - previewing the merge, moving to the record you want in the data source, then saving that document as a PDF

    If you are just previewing, then it is more likely that you wil end up with a mergefield name with chevrons, e.g.  <<RFI Date>> in the merge output.

    Is it a single field { MERGEFIELD "RFI Date" }, or what?

    The fact that you call it "table merge date" may be significant - I wonder whether you are attempting a "one-many" merge, for example.



    Peter Jamieson

    Wednesday, January 8, 2014 6:54 PM
  • Thanks Peter.  That portion is definitely in the body.  The viewing process can go one of 2 ways, you hit the view document button and the data merges into word, and displays as a pdf automatically.  Second way is to hit a different button which opens as a docx files and then someone could edit if they wanted to and send out as a word doc or save as pdf.

    What I have in the dotx file is a word table with 6 columns, with a merge field in each cell. 

    Wednesday, January 8, 2014 7:19 PM
  • OK,

    So what is actually executing when you hit these buttons? In particular, can you stop the process at the point where the merge operation has taken place but no PDF has been generated?

    (Any code you could post here might be relevant, but if that's not possible, a general outline of the code would be useful).

    I get the impression that if you leave the { INCLUDEPICTURE } fields out, the rest of the merge works how you want, but when you put them in, you don't get the chevrons in the PDF. There could be a simple explanation for that, but right now it doesn't spring to mind - my best guess would be to assume that some code (VBA, for example), was now failing as a result of the presence of the { INCLUDEPICTURE } fields and that other fields in the document were not being updated properly.


    Peter Jamieson

    Wednesday, January 8, 2014 7:43 PM
  • During option 1, the stored procedure is in the software and cannot be stopped.  During option 2, you just hit the open as .docx file button and word pops up. 

    If you could provide assistance of giving you that code I would be more than happy to provide.  You are a bit over my head at this point ;)

    Thanks again.

    Thursday, January 9, 2014 2:55 PM
  • Well, things may get tricky at this point, depending on who wrote the code, what type of code it is, where it is and how much of it there is. If you're not familiar with the code yourself, it is likely to be hard to find and interpret. But if you want to try...


    First, if you're using a third party product then the chances are that you wouldn't be able to get at the code anyway. If it's proprietary code, perhaps written by someone else in your company, you might have to ask someone for the source code, particularly if it's .NET code (C# or VB.NET, say). If it's VBA, then roughly speaking, the code will either be in the document itself (it would be a .docm or a .doc) or in a template/addin (a .dotm usually).

    If it's a template/addin, you can have a look at the current list of Addins in Word using FIle->Options->Addins. That may give you a clue as to what type of addin you have. Also, since VBA code can be "obfuscated", you may not be able to see anything even doing the following...

    To get at any VBA code in a .docm or .dotm, you would need to
     a. enable the Developer tab in Word, if necessary, by checking the relevant box in the right-hand column in via File->Options->Customize Ribbon

     b. click the Developer Tab, then the Visual Basic icon at the left hand end

     c. Have a look down the list of projects and see if you can spot the one that is providing the functionality you describe.

     d. If it's a .dotm, I think you will need to open the .dotm using Word's normal file->open command. While it's attached/opened as a template, you can't usually get at the VBA.

    If you manage to open the correct template/document, the code is organised under that particular project, in ThisDocument, in "Forms" (possibly), "Modules" and "Class modules". You can double-click on each one to see what's in there. Whether any of it will make any sense is another matter!

     

    Peter Jamieson

    • Marked as answer by Tony Chen CHN Friday, January 24, 2014 2:56 AM
    Thursday, January 9, 2014 4:02 PM