Dim d As String, fn As String
d = Dir("D:\123\" & Trim(Text1.Text) & "*.PDF")
Do Until d = ""
fn = d
d = dir
Loop
If fn = "" Then
MsgBox "文件未找到!"
Else
MsgBox "找到的文件是D:\123\" & fn
End If
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 inputStr As String '
Dim R As Long
Dim i As Integer, tmpStr As String
Dim filelist As FileListBox
inputStr = "LN123" '输入的图号
Set filelist = Me.Controls.Add("VB.FileListBox", "filelist")
filelist.Path = "C:\" '文件所在路径
filelist.Pattern = inputStr & "_?_*.pdf"
If filelist.ListCount > 0 Then
tmpStr = filelist.List(0)
For i = 1 To filelist.ListCount - 1
'Debug.Print filelist.List(i)
If filelist.List(i) > tmpStr Then
tmpStr = filelist.List(i)
End If
Next
R = ShellExecute(Me.hWnd, "Open", filelist.Path & tmpStr, "", "", vbNormalFocus) '打开文件
End If
Me.Controls.Remove filelist.Name
Set filelist = Nothing
End Sub
上次不是写给你了吗?还有什么不对的吗?或则哪里有问题?