Hallo Zusammen
Ich möchte mittels Doppelklick eine Listboxeintrag mit Excel öffnen.
Kann mir jemand den Code angeben. Ich kann zwar einen bestimmten Eintrag per Pfadangabe öffnen aber wie teile ich bei mehreren Einträgen mit, welches der Doppelgeklickte ist.
Form hat 2 Textboxen,4 Labels, 1 Listbox, 1 Commandbutton
Gruss Stoff
Ich möchte mittels Doppelklick eine Listboxeintrag mit Excel öffnen.
Kann mir jemand den Code angeben. Ich kann zwar einen bestimmten Eintrag per Pfadangabe öffnen aber wie teile ich bei mehreren Einträgen mit, welches der Doppelgeklickte ist.
Form hat 2 Textboxen,4 Labels, 1 Listbox, 1 Commandbutton
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal _
hFindFile As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Const MAX_PATH = 259
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_COMPRESSED = &H800
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Sub Form_Load()
Text1.Text = "E:\Rechnungen"
Text2.Text = "*.*"
End Sub
Private Sub Command1_Click()
Dim Files() As String, X&
Dim DatCnt%, DirCnt%
ReDim Files(0 To 0)
Call GetAllFiles(Text1.Text, Text2.Text, Files)
List1.Clear
For X = 0 To UBound(Files) - 1
List1.AddItem Files(X)
If Left$(Files(X), 2) = ">>" Then
DirCnt = DirCnt + 1
Label5.Caption = DirCnt
Label5.Refresh
Else
DatCnt = DatCnt + 1
Label6.Caption = DatCnt
Label6.Refresh
End If
Next X
End Sub
Private Sub GetAllFiles(ByVal Root$, ByVal Patt$, ByRef Field$())
Dim File$, hFile&, FD As WIN32_FIND_DATA
If Right(Root, 1) <> "\" Then Root = Root & "\"
hFile = FindFirstFile(Root & Patt, FD)
If hFile = 0 Then Exit Sub
Do
File = Left(FD.cFileName, InStr(FD.cFileName, Chr(0)) - 1)
If (FD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) _
= FILE_ATTRIBUTE_DIRECTORY Then
If (File <> ".") And (File <> "..") Then
Field(UBound(Field)) = ">>" & Root & File
ReDim Preserve Field(0 To UBound(Field) + 1)
GetAllFiles Root & File, Patt, Field
End If
Else
Field(UBound(Field)) = " " & Root & File
ReDim Preserve Field(0 To UBound(Field) + 1)
End If
Loop While FindNextFile(hFile, FD)
Call FindClose(hFile)
End Sub
Private Sub List1_DblClick()
?
End Sub
Ich hoffe auf den goldenen TipPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal _
hFindFile As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Const MAX_PATH = 259
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Const FILE_ATTRIBUTE_ARCHIVE = &H20
Const FILE_ATTRIBUTE_COMPRESSED = &H800
Const FILE_ATTRIBUTE_DIRECTORY = &H10
Const FILE_ATTRIBUTE_HIDDEN = &H2
Const FILE_ATTRIBUTE_NORMAL = &H80
Const FILE_ATTRIBUTE_READONLY = &H1
Const FILE_ATTRIBUTE_SYSTEM = &H4
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Sub Form_Load()
Text1.Text = "E:\Rechnungen"
Text2.Text = "*.*"
End Sub
Private Sub Command1_Click()
Dim Files() As String, X&
Dim DatCnt%, DirCnt%
ReDim Files(0 To 0)
Call GetAllFiles(Text1.Text, Text2.Text, Files)
List1.Clear
For X = 0 To UBound(Files) - 1
List1.AddItem Files(X)
If Left$(Files(X), 2) = ">>" Then
DirCnt = DirCnt + 1
Label5.Caption = DirCnt
Label5.Refresh
Else
DatCnt = DatCnt + 1
Label6.Caption = DatCnt
Label6.Refresh
End If
Next X
End Sub
Private Sub GetAllFiles(ByVal Root$, ByVal Patt$, ByRef Field$())
Dim File$, hFile&, FD As WIN32_FIND_DATA
If Right(Root, 1) <> "\" Then Root = Root & "\"
hFile = FindFirstFile(Root & Patt, FD)
If hFile = 0 Then Exit Sub
Do
File = Left(FD.cFileName, InStr(FD.cFileName, Chr(0)) - 1)
If (FD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) _
= FILE_ATTRIBUTE_DIRECTORY Then
If (File <> ".") And (File <> "..") Then
Field(UBound(Field)) = ">>" & Root & File
ReDim Preserve Field(0 To UBound(Field) + 1)
GetAllFiles Root & File, Patt, Field
End If
Else
Field(UBound(Field)) = " " & Root & File
ReDim Preserve Field(0 To UBound(Field) + 1)
End If
Loop While FindNextFile(hFile, FD)
Call FindClose(hFile)
End Sub
Private Sub List1_DblClick()
?
End Sub
Gruss Stoff