![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2004
Location: Spring, TX
Posts: 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")
|
|
|
|
|
|
#2 |
|
Join Date: Oct 2002
Location: Turkiye
Posts: 832
|
Try using a WebBrowser control and use the code below;
Code:
WebBrowser1.Navigate "about: |
|
|
|
|
|
#3 |
|
Join Date: Mar 2004
Location: Spring, TX
Posts: 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...
|
|
|
|
|
|
#4 | |
|
Join Date: Oct 2002
Location: Turkiye
Posts: 832
|
Quote:
|
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,771
|
What follows is a modification from
http://vbnet.mvps.org/index.html?cod...ilenocache.htm Put the following in a standard module: Option Explicit 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 ** Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _ ****Alias "DeleteUrlCacheEntryA" ( _ ****ByVal lpszUrlName As String) As Long Private Declare Function GetTempFileName Lib "kernel32" Alias _ ****"GetTempFileNameA" (ByVal lpszPath As String, _ ****ByVal lpPrefixString As String, ByVal wUnique As Long, _ ****ByVal lpTempFileName As String) As Long Private Declare Function SetFileAttributes Lib "kernel32" Alias _ ****"SetFileAttributesA" (ByVal lpFileName As String, _ ****ByVal dwFileAttributes As Long) As Long ** Private Const ERROR_SUCCESS As Long = 0 Private Const BINDF_GETNEWESTVERSION As Long = &H10 Private Const INTERNET_FLAG_RELOAD As Long = &H80000000 Private Const FILE_ATTRIBUTE_TEMPORARY = &H100 Private Function DownloadFile(sSourceUrl As String, _ ******************************sLocalFile As String) As Boolean ** **'Download the file. BINDF_GETNEWESTVERSION forces **'the API to download from the specified source. **'Passing 0& as dwReserved causes the locally-cached **'copy to be downloaded, if available. If the API **'returns ERROR_SUCCESS (0), DownloadFile returns True. ** DownloadFile = URLDownloadToFile(0&, _ ************************************sSourceUrl, _ ************************************sLocalFile, _ ************************************BINDF_GETNEWESTVERSION, _ ************************************0&) = ERROR_SUCCESS ** End Function Function LoadPictureUrl(sSourceUrl As String) As IPictureDisp ** Dim sLocalFile As String ** ** On Error GoTo err_h ** ** 'Create a buffer ** sLocalFile = String(260, 0) ** 'Get a temporary filename ** GetTempFileName "C:\", "KPD", 0, sLocalFile ** 'Remove all the unnecessary chr$(0)'s ** sLocalFile = Left$(sLocalFile, InStr(1, sLocalFile, Chr$(0)) - 1) ** 'Set the file attributes ** SetFileAttributes sLocalFile, FILE_ATTRIBUTE_TEMPORARY **'Attempt to delete any cached version of the file. ** DeleteUrlCacheEntry sSourceUrl ** ** If DownloadFile(sSourceUrl, sLocalFile) = True Then ******'hfile = FreeFile ******'Open sLocalFile For Input As #hfile ******'Text1.Text = Input$(LOF(hfile), hfile) ******'Close #hfile ******Set LoadPictureUrl = LoadPicture(sLocalFile) ******Kill sLocalFile ** Else ******'Create a bogus error ******Err.Raise 999 ** End If ** Exit Function err_h: ** Set LoadPictureUrl = LoadPicture("") End Function now, you can call this function like Private Sub Command1_Click() ** Dim Url As String ** Url = "http://www.mrexcel.com/board2/images/avatars/1739339495404fef2bc2773.gif" ** Image1.Picture = LoadPictureUrl(Url) End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|