.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...
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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>"
 
Upvote 0
Excellent. Going to read up on more details on this "new" control. Help menu doesn't seem to be much help on this topic...
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top