Microsoft 365 Récupération de l'image de la note dans UserForm

Francky79

XLDnaute Occasionnel
Bonjour le forum,

Est-il possible de récupérer l'image dans une note et de l'insérer dans un UserForm ?
Aucune idée sur le moyen de la faire.
Voir fichier en pièce jointe.
Merci pour votre aide,
 

Pièces jointes

  • Test commentaire.xlsm
    79 KB · Affichages: 5

Francky79

XLDnaute Occasionnel
Re,

Le problème vient de ce code:

VB:
Private Sub CommandButton1_Click()
    X = (ConvertAllShapeToWMF([Y6]))
Image1.Picture = LoadPicture(X)
Kill X
End Sub

Comment remplacer le [Y6] pour que sa fonctionne sur toutes les lignes de la colonne Y ?
Merci
 

Francky79

XLDnaute Occasionnel
Merci Bruno,

En faite pas besoin de bouton l'image se met directement dans l'userform.:)
Mais cela ne marche pas pour toutes les lignes et le code beaucoup trop compliqué pour moi.
Il y a t'il une solution pour que cela marche sur toutes les lignes ?
Merci de ton aide.
 

Pièces jointes

  • Francky79_Test commentaire.xlsm
    82.3 KB · Affichages: 3
C

Compte Supprimé 979

Guest
Francky79

Il y avait 2 soucis sur le code trouvé, ça ne semblait fonctionner qu'une fois et l'image supprimée était celle du commentaire :eek:

J'ai changé tout ça et je crée l'image à l'aide d'un graphique

Cela fonctionne parfaitement de mon côté, à voir de ton côté ;)

A+
 

Pièces jointes

  • Francky79_Test commentaire v3.xlsm
    84 KB · Affichages: 2

patricktoulon

XLDnaute Barbatruc
bonjour bruno
j'ai fait un peu d’élagage dans ta fonction
et je la renomme car la mienne c'est pour exporter en wmf le graphique exporte en gif ou jpeg


VB:
Public MonImg As String
Dim ImgTemp$
Sub V()
    Dim Lig As Long
    Lig = ActiveCell.Row
    Application.ScreenUpdating = False
    MonImg = ConvertAllShapeToJPG(Range("Y" & ActiveCell.Row))
    Application.ScreenUpdating = True
    With UserForm6
        .TextBox1.Text = ActiveCell.Value
        .TextBox2.Text = Range("B" & Lig).Value
        .TextBox3.Text = Range("C" & Lig).Value
        .TextBox7.Text = Range("E" & Lig).Value
        .TextBox4.Text = Range("G" & Lig).Value
        .TextBox5.Text = Range("H" & Lig).Value
        .TextBox6.Text = Range("I" & Lig).Value
        .TextBox8.Text = Range("AQ" & Lig).Value
        .TextBox9.Text = Range("J" & Lig).Value
        .TextBox10.Text = Range("K" & Lig).Value
        .TextBox11.Text = Range("L" & Lig).Value
        .TextBox12.Text = Range("M" & Lig).Value
        .TextBox13.Text = Range("O" & Lig).Value
        .TextBox14.Text = Range("N" & Lig).Value
        .TextBox15.Text = Range("Q" & Lig).Value
        .TextBox16.Text = Range("R" & Lig).Value
        .TextBox17.Text = Range("S" & Lig).Value
        .TextBox18.Text = Range("T" & Lig).Value
        .TextBox19.Text = Range("U" & Lig).Value
        Set commentaire = Range("W" & Lig).Comment
        If Not commentaire Is Nothing Then .TextBox20 = Range("W" & Lig).Comment.Text
        Set commentaire = Range("W" & Lig).Comment
        If Not commentaire Is Nothing Then .TextBox21 = Range("X" & Lig).Comment.Text
        .TextBox22.Text = Range("V" & Lig).Value
        .TextBox23.Text = Range("W" & Lig).Value
        .TextBox24.Text = Range("X" & Lig).Value
        .TextBox25.Text = Range("Y" & Lig).Value
        .Image1.Picture = LoadPicture(MonImg)
        .Show
    End With

End Sub

Function ConvertAllShapeToJPG(Rng As Range)
    Dim Shp As Shape, ShpRng As ShapeRange, oChrtO As ChartObject

    With Rng.Comment

        .Visible = True

        .Shape.CopyPicture

        ImgTemp = Environ("userprofile") & "\AppData\Local\Temp\a.jpg"    'si tu veux

        Set oChrtO = ActiveSheet.ChartObjects.Add(Left:=0, Top:=0, Width:=.Shape.Width, Height:=.Shape.Height)

        oChrtO.Chart.ChartArea.Format.Line.Visible = msoFalse

        .Visible = False

    End With

    With oChrtO.Chart

        .Paste

        .Export Filename:=ImgTemp, Filtername:="JPG"

        .Parent.Delete

    End With

    ConvertAllShapeToJPG = ImgTemp    ' return path image

    Application.OnTime Now + 0.0001, "killImage"
End Function

Sub killImage(): Kill ImgTemp: End Sub
pas la peine de faire un paste sur feuille pour re paster dans le chart
le height et width tu le prends sur le .comment.shape.(height ou width)
on y vois plus clair là d'un coup non?;)
et bien sur on supprime l'image temporaire crée aussi
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 211
Messages
2 086 286
Membres
103 170
dernier inscrit
HASSEN@45