none
Inserting a picture in my word template from a website! RRS feed

  • Question

  • Dear all,

    I have created a template which take information from our website, from example the following link would get the Hotel name and other information regarding this Hotel (Of course the template is connected to Microsoft Access database File (.mdb).

    Code:

    {HYPERLINK "http://web3.XYZ.de/web3/hotelData.do?client=de&activity=photo&hotelnumber={MERGEFIELD Hotel_Hotel_Key } \* MERGEFORMAT}

    Result:

     

    http://web3.xyz.de/web3/hotelData.do

    now, let’s imagine that the link will take us to this (which is working without problems):

    The question is!

    How Can I take the first shown picture from the website and include it in my template?

    Ps: Please be easy on me while explaning , I am totally new to the templates world :)


    Tuesday, July 29, 2014 8:56 AM

Answers

  • Hi Zayed_Germany,

    You’re using Office 2003, right? I think it’s possible with code.

    I’m not going to tell you the details, but I’ll give you some suggestions about how to do this.

    1. If you have Visual Studio installed on your machine, you could create a Word Add-In project, use managed code to download the picture you want from the hyperlink. WebClient or HttpWebRequest class will help you to download the html content or the image based on the given URL.

    2. This is also possible in VBA. Use URLDownloadToFile function to download the picture as a file, then insert the file into the Word document.

    For how to use this function in VBA, please take a look at this sample:

    Private Declare Function URLDownloadToFile Lib   "urlmon" _

      Alias   "URLDownloadToFileA" (ByVal pCaller As Long, _

      ByVal szURL As String,   ByVal szFileName As String, _

      ByVal dwReserved As   Long, ByVal lpfnCB As Long) As Long

    Public Sub DownloadFileWithURL()

        URLDownloadToFile 0, _

              "http://social.msdn.microsoft.com/Forums/getfile/505442", _

              "D:\505442.png", 0, 0

    End Sub

    Of course you have to get the first shown picture URL firstly based on the hyperlink. To do this you need to get the HTML source with the hyperlink, then retrieve the picture URL from the HTML source.

    For how to get the HTML source with URL, XMLHTTP object will help.

    Function GetHTML(URL As String) As String

        Dim HTML As String

        With   CreateObject("MSXML2.XMLHTTP")

            .Open   "GET", URL, False

            .Send

            GetHTML =   .ResponseText

        End With

    End Function

    If you’re not going to use any code, I think it’s very hard. By the way, this forum is for Word development questions, you may post in Word IT Pro forum for answers if you don’t want to use any code.

    Please let me know if I misunderstand you.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 30, 2014 5:59 AM
    Moderator
  • I was informed in the other post that If I posted here I would get an easier solution which requires no coding.

    If you were given such advice, then that advice was not very knowledgeable about the purpose of this forum, which is explicity FOR CODING, as Caillen Zhong points out.

    I also agree with her that this will NOT be possible without coding. Word has only the InsertPicture field code that can pull pictures in. It is designed to work with files saved in a "traditional" manner, on disk or in a network location. The only way I can imagine this to be possible is if you can get a direct network connection to a folder where these pictures are stored AND the database would need to supply the picture's file name (or the complete path).


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, August 3, 2014 6:26 AM
    Moderator

All replies

  • Hi Zayed_Germany,

    You’re using Office 2003, right? I think it’s possible with code.

    I’m not going to tell you the details, but I’ll give you some suggestions about how to do this.

    1. If you have Visual Studio installed on your machine, you could create a Word Add-In project, use managed code to download the picture you want from the hyperlink. WebClient or HttpWebRequest class will help you to download the html content or the image based on the given URL.

    2. This is also possible in VBA. Use URLDownloadToFile function to download the picture as a file, then insert the file into the Word document.

    For how to use this function in VBA, please take a look at this sample:

    Private Declare Function URLDownloadToFile Lib   "urlmon" _

      Alias   "URLDownloadToFileA" (ByVal pCaller As Long, _

      ByVal szURL As String,   ByVal szFileName As String, _

      ByVal dwReserved As   Long, ByVal lpfnCB As Long) As Long

    Public Sub DownloadFileWithURL()

        URLDownloadToFile 0, _

              "http://social.msdn.microsoft.com/Forums/getfile/505442", _

              "D:\505442.png", 0, 0

    End Sub

    Of course you have to get the first shown picture URL firstly based on the hyperlink. To do this you need to get the HTML source with the hyperlink, then retrieve the picture URL from the HTML source.

    For how to get the HTML source with URL, XMLHTTP object will help.

    Function GetHTML(URL As String) As String

        Dim HTML As String

        With   CreateObject("MSXML2.XMLHTTP")

            .Open   "GET", URL, False

            .Send

            GetHTML =   .ResponseText

        End With

    End Function

    If you’re not going to use any code, I think it’s very hard. By the way, this forum is for Word development questions, you may post in Word IT Pro forum for answers if you don’t want to use any code.

    Please let me know if I misunderstand you.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 30, 2014 5:59 AM
    Moderator
  • Hi,<o:p></o:p>

     

    I was informed in the other post that If I posted here I would get an easier solution which requires no coding.<o:p></o:p>

    please read the other post in complete.<o:p></o:p>

     

     

    Regards,<o:p></o:p>

    Zayed<o:p></o:p>

    Wednesday, July 30, 2014 8:56 AM
  • I find that hard to believe - there are no other replies to the thread in the link. In any event, that doesn't negate the need for you to provide cross-post links. Indeed, your reply suggests you have made other cross-posts of the same question that you also need to provide links for...

    Cheers
    Paul Edstein
    [MS MVP - Word]


    • Edited by macropodMVP Wednesday, July 30, 2014 9:24 PM typo
    Wednesday, July 30, 2014 9:02 AM
  • I was informed in the other post that If I posted here I would get an easier solution which requires no coding.

    If you were given such advice, then that advice was not very knowledgeable about the purpose of this forum, which is explicity FOR CODING, as Caillen Zhong points out.

    I also agree with her that this will NOT be possible without coding. Word has only the InsertPicture field code that can pull pictures in. It is designed to work with files saved in a "traditional" manner, on disk or in a network location. The only way I can imagine this to be possible is if you can get a direct network connection to a folder where these pictures are stored AND the database would need to supply the picture's file name (or the complete path).


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, August 3, 2014 6:26 AM
    Moderator
  • Use INCLUDEPICTURE and Under that Use MailMerge Filed

    Something like that

    { INCLUDEPICTURE { MERGEFIELD "Picture" } \* MERGEFORMAT }

    Friday, July 24, 2015 1:34 PM