.Picture property question

yee388

Well-known Member
Joined
Mar 7, 2004
Messages
1,374
Can I use a web location for the .Picture source on my Image control?

This is giving me some errors...

Code:
Image1.Picture = LoadPicture("http://www.mywebsitehere.com/MyFolder/Test.jpg")
NOTE: This is just example text.. don't try to go to the link...
 

Haluk

Rules Violation
Joined
Oct 26, 2002
Messages
1,075
Try using a WebBrowser control and use the code below;

Code:
WebBrowser1.Navigate "about:<html><body scroll='no'>[img]http://www.mrexcel.com/board2/images/newlogog.jpg[/img]</img></body></html>"
 

yee388

Well-known Member
Joined
Mar 7, 2004
Messages
1,374
Excellent. Going to read up on more details on this "new" control. Help menu doesn't seem to be much help on this topic...
 

Haluk

Rules Violation
Joined
Oct 26, 2002
Messages
1,075
Help menu doesn't seem to be much help on this topic...
That's true because it is not an OfficeVBA control........ actually, it is a VB control.
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
What follows is a modification from

http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htm

Put the following in a standard module:

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> URLDownloadToFile <SPAN style="color:#00007F">Lib</SPAN> "urlmon" Alias _
    "URLDownloadToFileA" (<SPAN style="color:#00007F">ByVal</SPAN> pCaller <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> szURL <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> szFileName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> dwReserved <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> lpfnCB <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
  
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> DeleteUrlCacheEntry <SPAN style="color:#00007F">Lib</SPAN> "Wininet.dll" _
    Alias "DeleteUrlCacheEntryA" ( _
    <SPAN style="color:#00007F">ByVal</SPAN> lpszUrlName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> GetTempFileName <SPAN style="color:#00007F">Lib</SPAN> "kernel32" Alias _
    "GetTempFileNameA" (<SPAN style="color:#00007F">ByVal</SPAN> lpszPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> lpPrefixString <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> wUnique <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> lpTempFileName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> SetFileAttributes <SPAN style="color:#00007F">Lib</SPAN> "kernel32" Alias _
    "SetFileAttributesA" (<SPAN style="color:#00007F">ByVal</SPAN> lpFileName <SPAN style="color:#00007F">As</SPAN> String, _
    <SPAN style="color:#00007F">ByVal</SPAN> dwFileAttributes <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>

  
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Const</SPAN> ERROR_SUCCESS <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = 0
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Const</SPAN> BINDF_GETNEWESTVERSION <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = &H10
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Const</SPAN> INTERNET_FLAG_RELOAD <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> = &H80000000
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Const</SPAN> FILE_ATTRIBUTE_TEMPORARY = &H100


<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Function</SPAN> DownloadFile(sSourceUrl <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, _
                              sLocalFile <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>
  
  <SPAN style="color:#007F00">'Download the file. BINDF_GETNEWESTVERSION forces</SPAN>
  <SPAN style="color:#007F00">'the API to download from the specified source.</SPAN>
  <SPAN style="color:#007F00">'Passing 0& as dwReserved causes the locally-cached</SPAN>
  <SPAN style="color:#007F00">'copy to be downloaded, if available. If the API</SPAN>
  <SPAN style="color:#007F00">'returns ERROR_SUCCESS (0), DownloadFile returns True.</SPAN>
   DownloadFile = URLDownloadToFile(0&, _
                                    sSourceUrl, _
                                    sLocalFile, _
                                    BINDF_GETNEWESTVERSION, _
                                    0&) = ERROR_SUCCESS
  
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN>

<SPAN style="color:#00007F">Function</SPAN> LoadPictureUrl(sSourceUrl <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> IPictureDisp
   <SPAN style="color:#00007F">Dim</SPAN> sLocalFile <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
  
   <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> err_h
  
   <SPAN style="color:#007F00">'Create a buffer</SPAN>
   sLocalFile = <SPAN style="color:#00007F">String</SPAN>(260, 0)
   <SPAN style="color:#007F00">'Get a temporary filename</SPAN>
   GetTempFileName "C:\", "KPD", 0, sLocalFile
   <SPAN style="color:#007F00">'Remove all the unnecessary chr$(0)'s</SPAN>
   sLocalFile = Left$(sLocalFile, InStr(1, sLocalFile, Chr$(0)) - 1)
   <SPAN style="color:#007F00">'Set the file attributes</SPAN>
   <SPAN style="color:#00007F">Set</SPAN>FileAttributes sLocalFile, FILE_ATTRIBUTE_TEMPORARY

  <SPAN style="color:#007F00">'Attempt to delete any cached version of the file.</SPAN>
   DeleteUrlCacheEntry sSourceUrl
  
   <SPAN style="color:#00007F">If</SPAN> DownloadFile(sSourceUrl, sLocalFile) = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN>

      <SPAN style="color:#007F00">'hfile = FreeFile</SPAN>
      <SPAN style="color:#007F00">'Open sLocalFile For Input As #hfile</SPAN>
      <SPAN style="color:#007F00">'Text1.Text = Input$(LOF(hfile), hfile)</SPAN>
      <SPAN style="color:#007F00">'Close #hfile</SPAN>
      <SPAN style="color:#00007F">Set</SPAN> LoadPictureUrl = LoadPicture(sLocalFile)
      Kill sLocalFile
   <SPAN style="color:#00007F">Else</SPAN>
      <SPAN style="color:#007F00">'Create a bogus error</SPAN>
      Err.Raise 999
   <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>

   <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Function</SPAN>
err_h:
   Set LoadPictureUrl = LoadPicture("")
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>

now, you can call this function like

<font face=Courier New>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Command1_Click()
   <SPAN style="color:#00007F">Dim</SPAN> Url <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
   Url = "http://www.mrexcel.com/board2/images/avatars/1739339495404fef2bc2773.gif"
   Image1.Picture = LoadPictureUrl(Url)
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 

Forum statistics

Threads
1,085,546
Messages
5,384,373
Members
401,890
Latest member
Angela7

Some videos you may like

This Week's Hot Topics

Top