XL 2019 Incorporer gif animé dans userform

Tempus

XLDnaute Junior
Bonjour le forum, bonjour à tous,

Je souhaiterais incorporer dans mon userform un gif animé.

J'ai testé quelques bout de code vb mais sans succès,voir ci dessous.
Mon fichier excel est en pièce jointe avec le gif.

Merci à vous.

'Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
'Me.WebBrowser1.Navigate2 "E:\gp.gif"
'End Sub
'Private Sub UserForm2_Initialize()
'WebBrowser1.Navigate _
' "about:<html><body scroll='no'>" & _
' "<img src='C:\gp.gif'></img></body></html>"
'DoEvents
'End Sub
'Private Sub WebBrowser1()
'Worksheet_Activate()
'WebBrowser1.Navigate "E:\gp.gif"
'End Sub

'Sub Gif()
' WebBrowser1.Navigate "C:\gp.gif"""
'End Sub
'Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
'WebBrowser1.Navigate "E:\gp.gif"
'End Sub
'Private Sub UserForm2_Initialize()
'WebBrowser1.Navigate _
'"about:<html><body scroll='no'>" & _
'"<img src='E:\gp.gif'></img></body>"
'End Sub


'StatusTextChange(ByVal Text As String)
'Private Sub UserForm2_Initialize()
'WebBrowser1.Navigate _
' "about:<html><body scroll='no'>" & _
' "<img src='C:\gp.gif'></img></body></html>"
'DoEvents
'End Sub
 

Pièces jointes

  • Tempus- gif à incorporer.xlsm
    67.5 KB · Affichages: 26
  • gp.gif
    gp.gif
    94.4 KB · Affichages: 26
Solution
a ben c'est un exemple complet tu peux tres bien te passer de la boite de dialogue et tout y couinti

demo a l'ouverture
VB:
Private Sub UserForm_Activate()
    Dim fichier, maxWidth&, PToPx#, H&
    With ActiveWindow.ActivePane
        PToPx = (.PointsToScreenPixelsY(72) - .PointsToScreenPixelsY(0)) / 72
    End With
    maxWidth = 100
    fichier = "C:\Users\polux\DeskTop\gp.gif" ' change le chemin de ton fichier ici
    With WebBrowser1
        .Navigate "about:blank"
        .Document.write "<body><img></img/></body>"
        .Document.body.Style.margin = 0
        With .Document.getelementsbytagname("IMG")(0)
            .src = fichier
            .Style.Width = maxWidth & "px"
            H = .offsetheight
        End With...

Eric C

XLDnaute Barbatruc
Bonjour le forum
Bonjour Tempus

Après avoir placé un WebBrowser sur ton USF, tu places ce code dans l'Initialize de ton USF:
VB:
' Insérer un Gif Animé dans l'userform
' Vériland Octobre 2003
Dim Gif As Variant
Gif = "C:\a\gp.gif"              ===> chemin à adapter
WebBrowser1.Navigate Gif

Il te faudra également réduire les dimensions de ton gif qui sont trop grandes pour que celui-ci soit placé en temps que logo (Si les dimensions sont trop importantes, alors les scrollbars de ton WebBrowser apparaîtront.
Bon fin de journée à toutes & à tous et protégez vous.
Eric c
 

patricktoulon

XLDnaute Barbatruc
bonjour
teste cela
met un webbrowser et un bouton dans un userform c'est tout!!!

la taille du webbrowser on s'en fou!!!on va l'ajuster automatiquement

et colle lui ce code
VB:
Private Sub CommandButton1_Click()
    Dim fichier, maxWidth&, PToPx#, H&
    fichier = Application.GetOpenFilename("images Files (*.jpg;*.png;*.gif;*.tiff), *.jpg;*.png;*.gif;*.tiff", 1, "ouvrir un fichier")
    maxWidth = 100
    With ActiveWindow.ActivePane
        PToPx = (.PointsToScreenPixelsY(72) - .PointsToScreenPixelsY(0)) / 72
    End With
    With WebBrowser1
        .Document.body.Style.margin = 0
        With .Document.getelementbyid("image1")
            .src = fichier
            .Style.Width = maxWidth & "px"
            H = .offsetheight
        End With
        .Width = maxWidth / PToPx + 15
        .Height = H / PToPx
    End With
End Sub

Private Sub UserForm_Activate()
    With WebBrowser1
        .Navigate "about:blank"
        .Document.write "<body><img id=image1></img/></body>"
    End With
End Sub

voila clique sur ton bouton et choisi un gif ou jpeg ou png ou tiff
et voila
le webbrowser fera 100 pixel/ptopx (ptopix=conversion point/pixel)de large et son height sera pris par le offsetheight de l’élément image1 du document html converti aussi en point
démonstration
au départ le userform est comme ca
Capture.JPG


a l'arrivée c'est comme ca
demo5.gif


voila ;)
 

patricktoulon

XLDnaute Barbatruc
a ben c'est un exemple complet tu peux tres bien te passer de la boite de dialogue et tout y couinti

demo a l'ouverture
VB:
Private Sub UserForm_Activate()
    Dim fichier, maxWidth&, PToPx#, H&
    With ActiveWindow.ActivePane
        PToPx = (.PointsToScreenPixelsY(72) - .PointsToScreenPixelsY(0)) / 72
    End With
    maxWidth = 100
    fichier = "C:\Users\polux\DeskTop\gp.gif" ' change le chemin de ton fichier ici
    With WebBrowser1
        .Navigate "about:blank"
        .Document.write "<body><img></img/></body>"
        .Document.body.Style.margin = 0
        With .Document.getelementsbytagname("IMG")(0)
            .src = fichier
            .Style.Width = maxWidth & "px"
            H = .offsetheight
        End With
        .Width = maxWidth / PToPx + 15
        .Height = H / PToPx
    End With
End Sub
c'est toujours toi qui décide la taille de ton logo dans le userform avec maxwidth
quand on redim un tag (IMG) non stylé dans un document html c'est comme les shapes pour excel il y a le lockaspectratio qui fait que quand tu redim un coté le reste suit proportionnellement
donc le principe est simple tu redim le width en pixel et tu récupère le offsetheight converti en point qui servira a redimensionner le webbrowser en hauteur
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 046
Messages
2 084 844
Membres
102 686
dernier inscrit
Franck6950