我怎么才能在打开指定文件时,如果找不到文件,只显示提示,而不打开文件夹,麻烦高手帮我改改
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
Private Sub Command1_Click()
Dim m, n, a, b, d As String
Dim sFile As String
On Error GoTo err
m = Month(Date)
n = Day(Date)
If Len(CStr(m)) = 2 Then
a = CStr(m)
ElseIf Len(CStr(m)) = 1 Then
a = "0" + CStr(m)
End If
If Len(CStr(n)) = 2 Then
b = CStr(n)
ElseIf Len(CStr(n)) = 1 Then
b = "0" + CStr(n)
End If
d = "HB" & a & b & "08"
sFile = Dir("c:\zwx\" & d & ".URP")
ShellExecute Me.hwnd, "open", "c:\zwx\" & sFile, "", "", vbNormalFocus
sFile = Dir
Exit Sub
err:
MsgBox "没有找到文件,请查看是否存在"
End Sub
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
Private Sub Command1_Click()
Dim m, n, a, b, d As String
Dim sFile As String
On Error GoTo err
m = Month(Date)
n = Day(Date)
If Len(CStr(m)) = 2 Then
a = CStr(m)
ElseIf Len(CStr(m)) = 1 Then
a = "0" + CStr(m)
End If
If Len(CStr(n)) = 2 Then
b = CStr(n)
ElseIf Len(CStr(n)) = 1 Then
b = "0" + CStr(n)
End If
d = "HB" & a & b & "08"
sFile = Dir("c:\zwx\" & d & ".URP")
ShellExecute Me.hwnd, "open", "c:\zwx\" & sFile, "", "", vbNormalFocus
sFile = Dir
Exit Sub
err:
MsgBox "没有找到文件,请查看是否存在"
End Sub