Afficher un message
Vieux 21/05/2006, 19h58   #3 (permalink)
Thomas
Guest
 
Messages: n/a
Par défaut Re:images et commentaires dans userform

Bonjour le Forum,

Je ne pense pas qu'il souhaite afficher le nom du fichier texte mais bien le texte qu'il contient

tu dois utiliser Open for input #1

voici un exemple :
Code:
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
Bien à vous
Thomas

PS: il faut mettre le fichier dans le meme dossier que les images(jpg) et les fichiers txt [file name=image_20060521185852.zip size=12267]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/image_20060521185852.zip[/file]
Fichiers attachés
Type de fichier : zip image_20060521185852.zip (12,0 Ko, 14 affichages)
  Réponse avec citation