Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert image form url or web

Status
Not open for further replies.
Will copying it and pasting to Word doc not work?

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
You do not need IIS for this to work. This should work for any Office app.

Make a reference to the COM object WinHTTP.dll - to use the LoadPicture property of an ActiveX control. This has an ActiveX Image control, named WebImage. This could easily be a checkbox, where the image is the checkbox picture. You could then fire an event when the user "checks" the picture.

The procedure creates a binary file of a JPG ( GIF works as well) and writes it, as text. It then loads it as a picture.

Code:
Sub GetWebImage()
Dim WinHttpReq As WinHttp.WinHttpRequest
' Create an instance of the WinHTTPRequest ActiveX object.
Set WinHttpReq = New WinHttpRequest
' Create an array to hold the response data.
 Dim d() As Byte
    
' Assemble an HTTP Request.
WinHttpReq.Open "GET", _
         "http://[i]qualified path[/i].jpg", False

' Send the HTTP Request.
WinHttpReq.Send
 
' Put response data into a file.
    Open "temp.gif" For Binary As #1
    d() = WinHttpReq.ResponseBody
    Put #1, 1, d()
    Close
    
' Load the data file as a picture.
    WebImage.Picture = LoadPicture("temp.gif")
End Sub

Gerry
 
Thanks gerry. Sounds like a lot to be able to "add an image" to a word doc (that will be saved as html) from an existing web server. I guess I would have to make a template file with the VBA and pass this out to portal content admins.
 
Huh? The above has nothing to do with saving the document as HTML. It is a Word document. It could be saved as HTML, but it does not have to be. This can be done as "live", as long as there is a live connection. It uses http protocol to call the file.

A template? It does not have to be. In fact, there are some distinct advantages to keeping it NOT a template. You would not have to make sure there was a reference to WinHTTP.dll, the originating document already has. Specific DLL references are not passed on to the child document, the one created from a template.

You have not stated exactly what you want to do. Pass it on to the portal content admins. For what purpose? Surely a portal content admin would have direct access to the file structure on the server. There are far, far, better ways of looking at a image file, than using Word to bring it in. There may be a reason for this, but could you tell me what it is?

Gerry
 
I apoplogize, I have not been clear. We have a portlet that diplays news. The content admin uses Word to build the article and then saves as html. This html file is uploaded to the portal and used by the portlet. We are changing portals and the admins want to continue to have this functionality as they are comfortable with Word (and management has decreed it).
They nnow want to put images into these Word docs that they save as html. When you click insert picutre, you get a browse for your local or network drives. I want to be able to provide them pics on a iis based image server, thus not requiing the upload of the _files folder that is created when you save as html.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top