AW: Probelme mit 2 Bild
31.08.2018 11:39:41
Nepumuk
Hallo Marta,
erweitere die ListBox auf 3 Spalten. Dann so:
Private Sub UserForm_Initialize()
ComboBox1.RowSource = "Tabelle2!$A$1:$A$36"
ComboBox3.RowSource = "Tabelle2!$E$3:$E$5"
Dim lZeile As Long
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
ListBox1.Clear
With Tabelle1
For lZeile = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
ListBox1.AddItem .Cells(lZeile, 1).Text
ListBox1.List(lZeile - 2, 1) = .Cells(lZeile, 5).Text
ListBox1.List(lZeile - 2, 2) = .Cells(lZeile, 7).Text
Next lZeile
End With
End Sub
'Klick auf die ListBox Ereignisroutin
Private Sub ListBox1_Click()
Dim strFile As String
Dim lZeile As Long
With ListBox1
If .ListIndex > -1 Then
'Prüfen ob Bild vorhanden
If .List(.ListIndex, 1) <> "" Then
strFile = Dir(.List(.ListIndex, 1), vbNormal)
If strFile <> "" Then
Set Image1.Picture = LoadPicture(.List(.ListIndex, 1))
Else
Set Image1.Picture = Nothing
MsgBox "Das Bild '" & .List(.ListIndex, 1) & "' wurde nicht gefunden!", vbInformation
End If
Else
Set Image1.Picture = Nothing
End If
If .List(.ListIndex, 2) <> "" Then
strFile = Dir(.List(.ListIndex, 2), vbNormal)
If strFile <> "" Then
Set Image1.Picture = LoadPicture(.List(.ListIndex, 2))
Else
Set Image1.Picture = Nothing
MsgBox "Das Bild '" & .List(.ListIndex, 2) & "' wurde nicht gefunden!", vbInformation
End If
Else
Set Image1.Picture = Nothing
End If
End If
End With
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
If ListBox1.ListIndex >= 0 Then
lZeile = 2
Do While Trim(CStr(Tabelle1.Cells(lZeile, 1).Value)) <> ""
If ListBox1.Text = Trim(CStr(Tabelle1.Cells(lZeile, 1).Value)) Then
TextBox1 = Trim(CStr(Tabelle1.Cells(lZeile, 1).Value))
TextBox2 = Tabelle1.Cells(lZeile, 2).Value
TextBox3 = Tabelle1.Cells(lZeile, 3).Value
TextBox4 = Tabelle1.Cells(lZeile, 4).Value
TextBox5 = Tabelle1.Cells(lZeile, 5).Value
TextBox6 = Tabelle1.Cells(lZeile, 6).Value
TextBox7 = Tabelle1.Cells(lZeile, 7).Value
Exit Do
End If
lZeile = lZeile + 1
Loop
End If
End Sub
Gruß
Nepumuk