加入代码
     文件对话框.CancelError = True
     On Error GoTo errhandler
      ...... errhandler:
      用户按了取消,代码就会跳到这里

解决方案 »

  1.   

    Private Sub Command1_Click()
        On Error GoTo nofile
        With CommonDialog1
            .InitDir = "c:\windows"
            .Filter = "*.txt"
            .CancelError = True
            .ShowOpen
        End With
        Label1.Caption = CommonDialog1.FileName
        Exit Subnofile:
        If Err.Number = 32755 Then
            Label1.Caption = "放弃操作"
            Exit Sub
        Else
            Label1.Caption = "其它错误"
        End If
    End Sub
      

  2.   

    http://www.csdn.net/Expert/topic/451/451495.shtm
      

  3.   

    同意楼上的同志们.
    关键是CancelError 属性,你按了取消按钮后会产生一个可捕获的错误