XL 2010 Insérer image dans une zone de texte

madoupa

XLDnaute Nouveau
Bonjour tout le monde
j'ai ce code pour insérer des images, SVP je veux modifier l'emplacement pour les insérer dans des zones de texte
merci
VB:
 Dim Emplacement As Range
  Dim img As Object
  Dim ShapeObj As Shape, i%
 
  'Boucle pour supprimer les images sauf le bouton
  For Each ShapeObj In Sheets("feuil1").Shapes
      If ShapeObj.Name = "Cible1" Then ShapeObj.Delete
  Next ShapeObj
  Sheets("feuil1").Activate
  If Application.Dialogs(xlDialogInsertPicture).Show Then
      For i = 1 To 2 'Boucle pour 2 images
        If i = 1 Then '1ère image
          Set Emplacement = Range("I15:I20") '1er emplacement
        Else 'sinon pour 2ème image, copie de la première
          ActiveSheet.Shapes.Range(Array("Cible1")).Select
          Selection.Copy
          ActiveSheet.Paste
          Set Emplacement = Range("I41:I46") '2ème emplacement
        End If
        Set img = ActiveSheet.DrawingObjects(ActiveSheet.Shapes.Count)
        With img.ShapeRange
          'Nommer l'image insérée (Pour la supprimer plus facilement ensuite)
          .Name = "Cible1" 'Nomme les images 1 ou 2
          .LockAspectRatio = msoFalse
          .Left = Emplacement.Left
          .Top = Emplacement.Top
          .Height = Emplacement.Height
          .Width = Emplacement.Width
          .ZOrder msoSendToBack
      End With
      Next i
 

p56

XLDnaute Occasionnel
Bonjour à tous,
Voici du code fonctionnel
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Sub Image_dans_Texte()
Dim ndf As Variant, W As Single, H As Single

    ndf = Choix_Image
    If Not ndf = False Then
        On Error Resume Next
        ActiveSheet.Shapes("_Test").Delete
        
        With ActiveSheet.Pictures.Insert(ndf)
            W = .Width
            H = .Height
            .Delete
        End With
    
        With ActiveSheet.Shapes.AddTextbox(1, 100, 50, W, H)
            .Fill.UserPicture ndf
            .Name = "_Test"
        End With
    End If
End Sub

Function Choix_Image() As String
    ChDrive (Left(ActiveWorkbook.Path, 1))
    ChDir ActiveWorkbook.Path
    Choix_Image = Application.GetOpenFilename("Fichiers images,*.jpg;*.gif;*.png")
End Function
P.
 

madoupa

XLDnaute Nouveau
Bonjour à tous,
Voici du code fonctionnel
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Sub Image_dans_Texte()
Dim ndf As Variant, W As Single, H As Single

    ndf = Choix_Image
    If Not ndf = False Then
        On Error Resume Next
        ActiveSheet.Shapes("_Test").Delete
       
        With ActiveSheet.Pictures.Insert(ndf)
            W = .Width
            H = .Height
            .Delete
        End With
   
        With ActiveSheet.Shapes.AddTextbox(1, 100, 50, W, H)
            .Fill.UserPicture ndf
            .Name = "_Test"
        End With
    End If
End Sub

Function Choix_Image() As String
    ChDrive (Left(ActiveWorkbook.Path, 1))
    ChDir ActiveWorkbook.Path
    Choix_Image = Application.GetOpenFilename("Fichiers images,*.jpg;*.gif;*.png")
End Function
P.
Merci, ça marche bien ton code
mais ce que je veux c'est d'insérer une image sur un textbox qui est déjà sur ma feuil pour ne pas prendre la forme des cellules, car l'image est un tampon rond.
merci
 

p56

XLDnaute Occasionnel
Et bien le principe est le même. Ici du code pour remplacer l'image du textbox nommé "_Test", en gardant les dimensions de l'image choisie
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Sub Remplace_Image_dans_Texte()
Dim ndf As Variant, W As Single, H As Single

    ndf = Choix_Image
    If Not ndf = False Then
        With ActiveSheet.Pictures.Insert(ndf)
            W = .Width
            H = .Height
            .Delete
        End With
       
        With ActiveSheet.Shapes("_Test")
            .Width = W
            .Height = H
            .Fill.UserPicture ndf
        End With
    End If
End Sub

Function Choix_Image() As String
    ChDrive (Left(ActiveWorkbook.Path, 1))
    ChDir ActiveWorkbook.Path
    Choix_Image = Application.GetOpenFilename("Fichiers images,*.jpg;*.gif;*.png")
End Function
 

madoupa

XLDnaute Nouveau
Et bien le principe est le même. Ici du code pour remplacer l'image du textbox nommé "_Test", en gardant les dimensions de l'image choisie
VB:
' Auteur : Pierre - P56 - http://tatiak.canalblog.com/
Sub Remplace_Image_dans_Texte()
Dim ndf As Variant, W As Single, H As Single

    ndf = Choix_Image
    If Not ndf = False Then
        With ActiveSheet.Pictures.Insert(ndf)
            W = .Width
            H = .Height
            .Delete
        End With
      
        With ActiveSheet.Shapes("_Test")
            .Width = W
            .Height = H
            .Fill.UserPicture ndf
        End With
    End If
End Sub

Function Choix_Image() As String
    ChDrive (Left(ActiveWorkbook.Path, 1))
    ChDir ActiveWorkbook.Path
    Choix_Image = Application.GetOpenFilename("Fichiers images,*.jpg;*.gif;*.png")
End Function
Merci beaucoup
il reste un seul souci c'est le code pour enlever le trait du contour de la textbox ça m'aidera beaucoup
merci d'avance
 

patricktoulon

XLDnaute Barbatruc
re
Bonjour a tous
j'aurais une question
ajouter un textbox formulaire par vba ok
mais par le menu le bouton est grisé(déactivé)
quelqu'un pourrait me dire pourquoi ?
demo.gif
 

Discussions similaires

Réponses
16
Affichages
1 K

Statistiques des forums

Discussions
312 192
Messages
2 086 054
Membres
103 109
dernier inscrit
boso_vs_viking