none
IncludeText and IncludePicture dont work as expected? RRS feed

  • Question

  • Hi Everyone,

    I am using INCLUDETEXT to add text to MS WORD file and after this immediately i use INCUDEPICTURE as following,

    {INCLUDETEXT "http://server/image location//DOCPROPERTY logo1 \* MERGEFORMAT }.txt "\!\* MERGEFORMAT}{INCLUDEPICTURE "http://server/image location/{DOCPROPERTY logo2 \* MERGEFORMAT}.jpg"\d \* MERGEFORMAT}

    I can see text file and image there but some how image shows up on next line not on the same line..If i manualy remove space it can come on the same line otherwise it is always on 2nd line..

    Please advise, how i can resolve this issue..

    Thanks,

    Khawar

    Tuesday, July 10, 2012 2:22 PM

Answers

  • Hi Khawar,

    First, your source documents will each need to have the same bookmark, spanning the range you want to replicate - not including the final paragraph mark unless you want it to appear in your target document. Your present INCLUDETEXT field is probably:

    {INCLUDETEXT "http://server/image location/{DOCPROPERTY logo1 \* MERGEFORMAT }.txt" \!\* MERGEFORMAT}

    It should become:

    {INCLUDETEXT "http://server/image location/{DOCPROPERTY logo1}.txt" "BookmarkName" \!}

    However, there are two things to note here:
    1. Your file extension is '.txt', which implies it is not a Word document. As you can't bookmark the contents of a txt file, you'll need to change to using a Word document instead (in which case the file extension becomes .doc or .docx)
    2. You are using the \! switch, which is of no effect with a txt file but may be useful with a doc or docx file, depending on its content.

    This also means you could actually have all of your source content in the same file by using {DOCPROPERTY logo1} for the bookmark names instead of for the filenames, thus:

    {INCLUDETEXT http://server/image location/Filename.doc "{DOCPROPERTY logo1}" \!}


    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Wednesday, July 11, 2012 10:12 PM Clarification re txt/doc files
    • Marked as answer by khawar hanif Friday, July 13, 2012 3:49 PM
    Wednesday, July 11, 2012 9:04 PM

All replies

  • Hi Khawar

    Which version of Word is involved?

    What do you mean by "if I manually remove space"?

    If there is insufficient room on a line, Word cannot keep two things on the same line. If I correctly understand what you mean be "manually remove space" then Word is behaving the way it should.

    One thing you could do would be to format the paragraph with a smaller font. Or you'd need to make wider margins.

    Note: I would removed ALL  \* MergeFormat switches from ALL the field codes. These could cause unexpected behavior, especially in relation to the font sizes. You might want to substitue  \* CharFormat switches for the MergeFormat, as these would force the fields to pick up the font characteristics you apply to the text.

    Please also note that the forums on MSDN target programming questions. Your question falls more into the category of end-user - programming code is not involved. The better place to ask such questions is the Answers forum as you'll find many more people there working at this level who can help you. Most of the people here specialize in programming:
    http://answers.microsoft.com/en-us/office/forum/word


    Cindy Meister, VSTO/Word MVP

    Tuesday, July 10, 2012 3:16 PM
    Moderator
  • Hi Cindy,

    Thank you so much for your quick reply.

    Hi Khawar

    Which version of Word is involved?

    I am using MS Word 2007

    What do you mean by "if I manually remove space"?

    I am using backspace to remove the space. I am not sure where the space is comming from.

    If there is insufficient room on a line, Word cannot keep two things on the same line. If I correctly understand what you mean be "manually remove space" then Word is behaving the way it should.

    Yes there is sufficient space. when i do backspace it moves to the same line and still have one space there.

    One thing you could do would be to format the paragraph with a smaller font. Or you'd need to make wider margins.

    Note: I would removed ALL  \* MergeFormat switches from ALL the field codes. These could cause unexpected behavior, especially in relation to the font sizes. You might want to substitue  \* CharFormat switches for the MergeFormat, as these would force the fields to pick up the font characteristics you apply to the text.

    Yes you are right with MergeFormat i am having hard time to apply font sizes. I will try your sugestions and will let you know.

    Please also note that the forums on MSDN target programming questions. Your question falls more into the category of end-user - programming code is not involved. The better place to ask such questions is the Answers forum as you'll find many more people there working at this level who can help you. Most of the people here specialize in programming:
    http://answers.microsoft.com/en-us/office/forum/word


    Cindy Meister, VSTO/Word MVP

    Thank you so much for your time, i will post my question there as well.

    Thanks,

    Khawar

    Tuesday, July 10, 2012 5:58 PM
  • Hi Khawar,

    Your problem is probably caused by the fact that, when you use INCLUDETEXT to incorprate a whole document, you get that document's final paragraph break(s) as well. If you don't want those, you need to bookmark the exact range you want to replicate and include the bookmark reference in your INCLUDETEXT field.

    Furthermore, quite apart from the issues regarding the \* MergeFormat switches Cindy mentioned, what you have posted does not represent valid field codes for either an INCLUDETEXT field or an INCLUDEPICTURE field.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, July 10, 2012 10:55 PM
  • Hi Paul,

    You are right INCLUDETEXT add paragraph break, i added image before INCLUDETEXT and there is no paragraph break. but i need to add picture after INCLUDETEXT..

    Can you please explain little bit more how i can achieve this? I am little bit confuse with bookmark and bookmark reference..

    "If you don't want those, you need to bookmark the exact range you want to replicate and include the bookmark reference in your INCLUDETEXT field."

    Thanks for your help.

    Thanks,

    Khawar

    Wednesday, July 11, 2012 3:54 PM
  • Hi Khawar,

    First, your source documents will each need to have the same bookmark, spanning the range you want to replicate - not including the final paragraph mark unless you want it to appear in your target document. Your present INCLUDETEXT field is probably:

    {INCLUDETEXT "http://server/image location/{DOCPROPERTY logo1 \* MERGEFORMAT }.txt" \!\* MERGEFORMAT}

    It should become:

    {INCLUDETEXT "http://server/image location/{DOCPROPERTY logo1}.txt" "BookmarkName" \!}

    However, there are two things to note here:
    1. Your file extension is '.txt', which implies it is not a Word document. As you can't bookmark the contents of a txt file, you'll need to change to using a Word document instead (in which case the file extension becomes .doc or .docx)
    2. You are using the \! switch, which is of no effect with a txt file but may be useful with a doc or docx file, depending on its content.

    This also means you could actually have all of your source content in the same file by using {DOCPROPERTY logo1} for the bookmark names instead of for the filenames, thus:

    {INCLUDETEXT http://server/image location/Filename.doc "{DOCPROPERTY logo1}" \!}


    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Wednesday, July 11, 2012 10:12 PM Clarification re txt/doc files
    • Marked as answer by khawar hanif Friday, July 13, 2012 3:49 PM
    Wednesday, July 11, 2012 9:04 PM
  • Hi,

       I would like to know how to add an image to MS Word.,using MS-interop Library.

    Thanks in Advance.

    Friday, July 13, 2012 5:24 AM
  • How about starting a new thread for that instead of hijacking and exiswting one.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, July 13, 2012 5:37 AM
  • How about starting a new thread for that instead of hijacking and exiswting one.

    Cheers
    Paul Edstein
    [MS MVP - Word]


    Okie
    Friday, July 13, 2012 5:43 AM
  • Hi Paul,

    It works like a charm.  I really appreciate your time and effort to resolve this issue. Once again thank you paul and Cindy. 

    Thanks,

    Khawar

    Friday, July 13, 2012 3:55 PM