Private Sub ComboBox1_Change()
afficher_image Me.ComboBox1.Text
lecture Me.ComboBox1.Text
End Sub
Private Sub UserForm_Activate()
recherche_image
End Sub
Sub recherche_image()
Application.FileSearch.NewSearch
Application.FileSearch.LookIn = ThisWorkbook.Path
Application.FileSearch.Filename = '.jpg'
Application.FileSearch.SearchSubFolders = False
Application.FileSearch.Execute
MsgBox ThisWorkbook.Path & Len(ThisWorkbook.Path)
nbFiches = Application.FileSearch.FoundFiles.Count
Me.Caption = nbFiches & ' Fichier(s) ' & quoi & ' trouvé(s)'
For i = 1 To nbFiches
Me.ComboBox1.AddItem Mid(Application.FileSearch.FoundFiles(i), Len(ThisWorkbook.Path) + 2, (Len(Application.FileSearch.FoundFiles(i)) - (Len(ThisWorkbook.Path) + 5)))
Next i
End Sub
Sub afficher_image(fichier As String)
Dim lect As String
lect = ThisWorkbook.Path & '\\' & fichier & '.jpg'
Me.Image1.Picture = LoadPicture(lect)
End Sub
Sub lecture(fichier As String)
On Error GoTo fin
Dim lect As String
Dim MyString As String
Dim MyString1 As String
lect = ThisWorkbook.Path & '\\' & fichier & '.txt'
Open lect For Input As #1
Do While Not EOF(1) ' Effectue la boucle jusqu'à la fin du fichier.
Input #1, MyString
MyString = MyString & Chr(10)
MyString1 = MyString1 & MyString
Loop
Close #1
Me.Label1.Caption = MyString1
Exit Sub
fin:
MsgBox 'Pas de fichier texte pour cette image!!'
End Sub