XL 2013 Importer une image d'un site Web

maval

XLDnaute Barbatruc
Bonjour,

J'ai une question, est-il possible d'importer une image d'un site Web dans contrôle image se trouvant sur un Usf.

Je vous remercie d'avance
 

job75

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Re,

J'ai compris, il faut sélectionner la Shape :

Code:
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
  .Shapes(1).Select
  If TypeName(Selection) <> "Range" Then
    w = Selection.Width: h = Selection.Height
    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
Edit : Selection.Delete inutile...

A+
 
Dernière édition:

job75

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Re,

Pour peaufiner on peut ajuster la hauteur du contrôle Image :

Code:
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
  .Shapes(1).Select
  If TypeName(Selection) <> "Range" Then
    w = Selection.Width: h = Selection.Height
    With .ChartObjects.Add(0, 0, w, h).Chart
      .Paste
      .Export chemin & "\MonImage.jpg", "JPG"
    End With
    Image1.Height = Image1.Width * h / w
    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
Edit : avec la propriété PictureSizeMode à 3 (Zoom) l'image remplit tout le contrôle.

A+
 
Dernière édition:

maval

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Bonjour,

Suite au code réaliser par Job75 que je salut et remercie encore, j’aimerais si possible après avoir récupérer mon image sur mon Usf pouvoir à l’aide d’un bouton envoyer cette image en Jpg dans un dossier Ex : C:\Image en prenant le nom qui se trouve dans le textbox.

Je joint mon fichier pour modèle

Je vous remercie d'avance
 

Pièces jointes

  • Classeur_Recherche_Image.xlsm
    244 KB · Affichages: 39

job75

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Bonjour maval, le fil,

La TextBox est bien inutile puisque le nom est affiché par la ComboBox.

Et le 2ème bouton aussi, utiliser simplement la macro que j'ai donnée sans "tuer" le fichier JPEG :

Code:
Private Sub CommandButton3_Click()
Dim chemin$, w, h
 chemin = "C:\Image\"
 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
   .Shapes(1).Select
   If TypeName(Selection) <> "Range" Then
     w = Selection.Width: h = Selection.Height
     With .ChartObjects.Add(0, 0, w, h).Chart
       .Paste
       .Export chemin & ComboBox1 & ".jpg", "JPG"
     End With
     Image1.Height = Image1.Width * h / w
     Image1.Picture = LoadPicture(chemin & ComboBox1 & ".jpg")
   End If
   .Delete 'suppression de la nouvelle feuille
 End With
 [A1].Copy [A1] 'facultatif, vide le presse-papiers
 Application.ScreenUpdating = True
 End Sub
A+
 

maval

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Bonjour Job

Je vous remercie encore, je voudrais finaliser mon Usf.
J'ai ajouter deux CheckBox a mon formulaire pour envoyer les photos dans les sous dossiers "Acteurs ou Réalisateurs"
C:\Film\Acteurs ou C:\Film\Réalisateurs en cochant la ou les checkBox car un acteur peut être aussi réalisateur. J'ai chercher sur la toile un code qui me permettrez d'ajouter cette fonction a votre code sans succès.
Je joint mon fichier et si vous avez le temps et l'envie de jeter un œil
Je vous en remercie d'avance et vous souhaite une bonne journée
 

Pièces jointes

  • importer-une-image-dun-site-web-classeur.xlsm
    159.9 KB · Affichages: 26

job75

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Bonjour maval, le forum,

Sur la toile pour si peu ?? Ce n'est quand même pas bien sorcier :

Code:
Private Sub CommandButton3_Click()
 Dim chemin1$, chemin2$, w, h
  chemin1 = "C:\Film\Acteurs\"
  chemin2 = "C:\Film\Réalisateurs\"
  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
    .Shapes(1).Select
    If TypeName(Selection) <> "Range" Then
      w = Selection.Width: h = Selection.Height
      Image1.Height = Image1.Width * h / w
      With .ChartObjects.Add(0, 0, w, h).Chart
        .Paste
        If CheckBox1 Then .Export chemin1 & ComboBox1 & ".jpg", "JPG": _
          Image1.Picture = LoadPicture(chemin1 & ComboBox1 & ".jpg")
        If CheckBox2 Then .Export chemin2 & ComboBox1 & ".jpg", "JPG": _
          Image1.Picture = LoadPicture(chemin2 & ComboBox1 & ".jpg")
      End With
    End If
    .Delete 'suppression de la nouvelle feuille
  End With
  [A1].Copy [A1] 'facultatif, vide le presse-papiers
  Application.ScreenUpdating = True
End Sub
Cela dit je n'ai pas testé.

Edit : coquille, j'avais oublié un slash...

Bonne journée.
 
Dernière édition:

maval

XLDnaute Barbatruc
Re : Importer une image d'un site Web

Bonjour Job

Et merci beaucoup de votre aide, j'ai un petit souci: j'ai un dossier nommé Film a l'intérieur un sous dossier nommé" Acteurs et un Réalisateurs" et quand j'enregistre la photo vas uniquement dans le dossier Film non pas dans le sous dossier approprier.
Et il enregistre comme ceci "ActeursAlain Delon RéalisateursAki Aleong"

Merci et bonne journée
 

Discussions similaires

Statistiques des forums

Discussions
312 576
Messages
2 089 843
Membres
104 289
dernier inscrit
red123