AW: Listbox mit Nanem Bilddateien füllen jpg bmp gif
15.10.2023 13:05:56
Alwin Weisangler
Hallo Roland,
Der Fehler entsteht, weil die Variable in der Initialize Prozedur nur deklariert ist und nicht Klassenweit in dem Userform erreichbar ist.
Warum im Ganzen Modul erreichbar:
Du willst ja sicherlich so wie bei mir im Beispiel was mit HV, QV und QT machen (verarbeiten) und da braucht diese Variable in der ganzen Klasse (Modul des Userforms) verfügbar.
dann so:
Option Explicit
Dim Format As String
Private Sub ListBox1_Click()
With Tabelle1
Bildgroesse_ermitteln (ListBox1.List(ListBox1.ListIndex, 1))
Cells(2, 2) = Format
End With
End Sub
Private Sub Userform_initialize()
Call Listbox1_initialisieren
End Sub
Private Sub Listbox1_initialisieren()
Dim Datei As String
Dim A As Boolean
Dim i As Long
Dim strOrdner As Variant
Dim Aufloesung As String
Dim Breite As Long
Dim Hoehe As Long
strOrdner = "D:"
ListBox1.Clear
Me.ListBox1.ColumnCount = 2
Me.ListBox1.ColumnWidths = "50;50"
Datei = Dir(strOrdner)
Do While Datei > ""
If Not InStr(1, Datei, ".jpg") = 0 Or Not InStr(1, Datei, ".gif") = 0 Or Not InStr(1, Datei, ".bmp") = 0 Then
ListBox1.AddItem Datei
ListBox1.List(ListBox1.ListCount - 1, 1) = strOrdner & Datei
End If
Datei = Dir()
Loop
End Sub
Private Function Bildgroesse_ermitteln(Quelldatei As String)
Dim objPicture As IPictureDisp
Dim Hoehe As Long
Dim Breite As Long
Set objPicture = LoadPicture(ListBox1.List(ListBox1.ListIndex, 1))
Breite = objPicture.Width
Hoehe = objPicture.Height
Set objPicture = Nothing
If Hoehe / Breite > 1 Then Format = "QV" 'Querformat
If Hoehe / Breite = 1 Then Format = "QT" 'Qudratformat
If Hoehe / Breite 1 Then Format = "HV" 'Hochformat
End Function
Gruß Uwe