ich muss ein Formular in Excel erstellen, in dem es mehrer Listboxen gibt, die aus einer externen xls-Datei befüllt werden. Kann ich es irgendwie geschickter machen, momentan benutze ich für das Befüllen der Listboxen für jede Listbox den eingefügten Code 1x. Geht das auch perfomanter (also dass nicht jedes mal die Datenbankdatei geöffnet und wieder geschlossen wird pro Listbox?
Ich bin für jeden Tipp dankbar!! Ach ja, das ganze muss in Excel sein, auch wenn sich Access dafür sicher besser eignen würde. Hier ein Beispiel-Code:
With Me.listshipper
.Clear ' remove existing entries from the listbox
' turn screen updating off,
' prevent the user from seeing the source workbook being opened
Application.ScreenUpdating = False
' open the source workbook as ReadOnly
Set SourceWB = Workbooks.Open("c:\DB.xls", _
False, True)
ListItems = SourceWB.Worksheets(1).Range("A2:A1000").Value
' get the values you want
SourceWB.Close False ' close the source workbook without saving changes
Set SourceWB = Nothing
Application.ScreenUpdating = True
ListItems = Application.WorksheetFunction.Transpose(ListItems)
' convert values to a vertical array
For i = 1 To UBound(ListItems)
.AddItem ListItems(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the first item
End With
Danke!
Maxx