Das könntest Du...
09.02.2017 07:44:38
Case
Hallo, :-)
... prinzipiell so machen: ;-)
Option Explicit
' Bedingte Kompilierung - wenn 64 Bit dann...
#If Win64 Then
Private Declare PtrSafe Function SearchTreeForFile Lib "imagehlp.dll" _
(ByVal RootPath As String, ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
' ... sonst...
#Else
Private Declare Function SearchTreeForFile Lib "imagehlp.dll" _
(ByVal RootPath As String, ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
#End If
' Bedingte Kompilierung - wenn 64 Bit dann...
#If Win64 Then
Private Declare PtrSafe 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
#Else
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
#End If
Private Const SW_MAXIMIZE = 3
' Dateierweiterung UND Pfad gegebenenfalls anpassen!!!
Const strPath As String = "C:\Temp\"
Const strEX As String = ".pdf"
Private Sub CommandButton1_Click()
' Variablendeklaration
' Stringvariable mit Puffer
Dim strPathName As String * 255
Dim strName As String
Dim lngTMP As Long
On Error GoTo Fin
' Textbox mit Inhalt?
If Trim(TextBox1.Text) "" Then
' Datei suchen, wenn gefunden ist der Rückgabewert ein Long ungleich 0
lngTMP = SearchTreeForFile(strPath, "*" & TextBox1.Text & "*" & strEX, strPathName)
If lngTMP = 0 Then
' Datei nicht vorhanden!
MsgBox "File not found!"
Else
' Puffer zurechtstutzen, überflüssige Leerzeichen weg
strPathName = Left$(strPathName, InStr(1, strPathName, vbNullChar) - 1)
strName = RTrim(strPathName)
' Datei öffnen
ShellExecute 0, "Open", strName, "", "", SW_MAXIMIZE
End If
End If
Fin:
' Wenn ein Fehler auftritt gib ihn aus mit Fehlernummer und Beschreibung
If Err.Number 0 Then MsgBox "Error: " & _
Err.Number & " " & Err.Description
End Sub
Anpassungen nicht vergessen!
Servus
Case