Attribution Image.Picture
L
Bonsoir à tous,
J'essai d'attribuer à l'image1 de mon userform une image présente dans mon dossier "Trombinoscope". Dans mon projet final, le dossier "trombinoscope" comporte des sous dossiers donc mon code commence par lister sur la "Feuil1 les noms des images présentes, pour ensuite attribuer l'image dont le nom est en cellule A1 à l'image1 mais c'est là que ça bloque : objet requis
Voici mon code... Si quelqu'un peut me renseigner sur mon erreur
Private Sub UserForm_Initialize()
Dim myPath As String
Dim myFile As String
Dim FSO As Object
Dim doss As Object
Dim Mag As String
Dim IM1 As String
Sheets("Feuil1").Activate
'--------------------------------------------------------------------------------------------------
myPath = ThisWorkbook.Path
myFile = Dir(myPath & "\Trombinoscope" & "\*.jpg")
c = 1
Do While myFile <> ""
Cells(c, 1) = myFile
myFile = Dir()
c = c + 1
Loop
'--------------------------------------------------------------------------------------------------
Set FSO = CreateObject("scripting.Filesystemobject")
Set doss = FSO.getfolder(ThisWorkbook.Path & "\Trombinoscope\" & Mag)
MsgBox doss.Files.count
If doss.Files.count = 1 Then USFTrombino.Height = 243: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 2 Then USFTrombino.Height = 243: USFTrombino.Width = 390: Label5.Left = 18
If doss.Files.count = 3 Then USFTrombino.Height = 243: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 4 Then USFTrombino.Height = 243: USFTrombino.Width = 390: Label5.Left = 18
If doss.Files.count = 5 Then USFTrombino.Height = 243: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 6 Then USFTrombino.Height = 243: USFTrombino.Width = 578: Label5.Left = 113
If doss.Files.count = 7 Then USFTrombino.Height = 393: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 8 Then USFTrombino.Height = 393: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 9 Then USFTrombino.Height = 393: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 10 Then USFTrombino.Height = 393: USFTrombino.Width = 484: Label5.Left = 66
If doss.Files.count = 11 Then USFTrombino.Height = 393: USFTrombino.Width = 578: Label5.Left = 113
If doss.Files.count = 12 Then USFTrombino.Height = 393: USFTrombino.Width = 578: Label5.Left = 113
If doss.Files.count = 13 Then USFTrombino.Height = 393: USFTrombino.Width = 673: Label5.Left = 160
If doss.Files.count = 14 Then USFTrombino.Height = 393: USFTrombino.Width = 673: Label5.Left = 160
Image1.Picture = ThisWorkbook.Path & "\Trombinoscope\" & Sheets("Feuil1").Range("A1").Value
Set FSO = Nothing
Set doss = Nothing
End Sub
Merci
M
Bonsoir,
Pb syntaxe !
Charger un fichier image pour l'affecter à la propriété Picture d'un contrôle Image :
... = LoadPicture(fichier)