Sub Main()
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Add "文本文件", "*.txt"
.InitialFileName = "ABC.txt"
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
If vrtSelectedItem = "ABC.txt" Then
MsgBox "你选择了: " & vrtSelectedItem
Else
MsgBox "请重新选择!"
End If
Next
End If
End With
Set fd = Nothing
End Sub
Sub Main()
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Add "文本文件", "*.txt"
.InitialFileName = "ABC.txt"
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
If right(vrtSelectedItem,7) = "ABC.txt" Then '更改一下条件
MsgBox "你选择了: " & vrtSelectedItem
Else
MsgBox "请重新选择!"
End If
Next
End If
End With
Set fd = Nothing
End Sub