Halo! Hier mal dein Code zum Lesen für die anderen.
Private Const sAdressDatei As String = "C:\Formblatt_Daten.xlsx"
Private Const sTabellenblatt2 As String = "Inhalt"
Private Sub UserForm_Initialize()
Dim oExcelApp As Object
Dim oExcelWorkbook As Object
Dim lZeile As Long
Set oExcelApp = CreateObject("Excel.Application")
Set oExcelWorkbook = oExcelApp.Workbooks.Open(sAdressDatei)
ListBox2.Clear
ListBox2.ColumnCount = 2
ListBox2.ColumnWidths = "0,9cm;2,5cm;2cm;1,2cm"
lZeile = 2
With oExcelWorkbook.Sheets(sTabellenblatt2)
Do While .Cells(lZeile, 1) <> ""
ListBox2.AddItem CStr(.Cells(lZeile, 2).Value)
.List(.ListCount - 1, 1) = .Cells(lZeile, 3).Value
lZeile = lZeile + 1
Loop
End With
oExcelWorkbook.Close False
oExcelApp.Quit
Set oExcelWorkbook = Nothing
Set oExcelApp = Nothing
End Sub
ALso was mir auffällt ist, dass du der Listbox 2 Spalten zuweist aber 4 breiten angibst - könnte schonmal ein Fehler sein. Du willst dann vermtl. in jede Spalte der Listbox was zuweisen. Dann würde ich das so ändern. Bei dir passt da die Zuordnung nicht gant. Bei .list nimmst du dz#urch das . ja das Sheet und nicht die Listbox. Probiere es mal so mit der Schleife
Do While .Cells(lZeile, 1) <> ""
ListBox2.AddItem
ListBox2.List(ListBox2.ListCount - 1, 0) = CStr(.Cells(lZeile, 2).Value)
ListBox2.List(ListBox2.ListCount - 1, 1) = .Cells(lZeile, 3).Value
lZeile = lZeile + 1
Loop
SChönen Abend noch.
|