'Dans un module standard
Public Const url As String = "http://www.monblogamoi.com/" 'url de l'image
Public chemin, Fichier, img As String
'À placer dans le module du formulaire
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
img = "tarzan.jpg"
Fichier = url & "/" & img
chemin = ThisWorkbook.Path & "\fichier"
URLDownloadToFile 0, Fichier, chemin, 0, 0
With Me
.Image1.Picture = LoadPicture(chemin)
End With
Mais je croyais qu'il était possible de copier la photo dans le presse papier et avec l'Usf coller dans le contrôle image.
Sub AfficheImage()
Dim chemin$, w, h
chemin = ThisWorkbook.Path
Application.DisplayAlerts = False 'si le fichier existe déjà
On Error Resume Next 's'il n'y a rien dans le presse-papiers
With ActiveSheet
.Paste
If Err Or TypeName(Selection) <> "Picture" Then Exit Sub
w = Selection.Width: h = Selection.Height: Selection.Delete
With .ChartObjects.Add(0, 0, w, h).Chart
.Paste
.Export chemin & "\MonImage.jpg", "JPG"
.Parent.Delete
End With
.[A1].Copy [A1] 'facultatif, vide le presse-papiers
End With
Image1.Picture = LoadPicture(chemin & "\MonImage.jpg")
Kill chemin & "\MonImage.jpg"
End Sub
Sub AfficheImage()
Dim chemin$, w, h
chemin = ThisWorkbook.Path
Application.DisplayAlerts = False 'si le fichier existe déjà
On Error Resume Next 's'il n'y a rien dans le presse-papiers
With ActiveSheet
.Paste
If Err Or TypeName(Selection) = "Range" Then Exit Sub
w = Selection.Width: h = Selection.Height: Selection.Delete
With .ChartObjects.Add(0, 0, w, h).Chart
.Paste
.Export chemin & "\MonImage.jpg", "JPG"
.Parent.Delete
End With
.[A1].Copy [A1] 'facultatif, vide le presse-papiers
End With
Image1.Picture = LoadPicture(chemin & "\MonImage.jpg")
Kill chemin & "\MonImage.jpg"
End Sub
Private Sub CommandButton3_Click()
Dim chemin$, w, h
chemin = ThisWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next 's'il n'y a rien dans le presse-papiers
Image1.Picture = LoadPicture("") 'RAZ
With Sheets.Add 'nouvelle feuille
.Paste
DoEvents
If TypeName(Selection) <> "Range" Then
w = Selection.Width: h = Selection.Height: Selection.Delete
With .ChartObjects.Add(0, 0, w, h).Chart
.Paste
.Export chemin & "\MonImage.jpg", "JPG"
End With
Image1.Picture = LoadPicture(chemin & "\MonImage.jpg")
Kill chemin & "\MonImage.jpg"
End If
.Delete 'suppression de la nouvelle feuille
End With
[A1].Copy [A1] 'facultatif, vide le presse-papiers
Application.ScreenUpdating = True
End Sub