先在窗体上放CommonDialog控件.
Private Sub cmdOpen_Click()
On Error GoTo Result
Dim strNeedFileName as string
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
strNeedFileName = CommonDialog1.FileName
Result:
Select Case Err.Number
Case Is = 32755
Exit Sub
Case Is = 20
Resume Next
Case Is = 0
Resume Next
Case Else
MsgBox Err.Number & Err.Description
Exit Sub
End Select
End Sub