我在使用Commondialog1.showSave后
怎么判断用户点选的是“确定”还是“取消”??

解决方案 »

  1.   

    If Err = cdlCancel Then Exit Sub
    为取消
      

  2.   

    Dim filename As String
        Commondialog1.ShowSave
        If Err = cdlCancel Then Exit Sub
        filename = Commondialog1.filename
    不对呀,还是会向下运行
      

  3.   

    On Error Resume Next
    Commondialog1.CancelError = True
    Commondialog1.DialogTitle = "保存文件"
    Commondialog1.FileName = ""
    '解释见上面
    Commondialog1.Filter = "文本文件(*.txt)|*.txt"
    Commondialog1.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
    Commondialog1.ShowSave
    If Err = cdlCancel Then Exit Sub
      

  4.   

    首先设置控件属性,该值指示当选取“取消”按钮时是否出错。
    CommonDialog1.CancelError = True
    CommonDialog1.Action = 1
     这时该属性设置为 True 时,无论何时选取“取消”按钮,均产生 32755 (cdlCancel) 号错误。
    这样再继续编错误号为32755的处理程序即可
      

  5.   

    Private Sub Command1_Click()
       '打开错误处理陷阱
       On Error GoTo ErrGoto
       '----------------------------------------------------
      
        Commondialog1.CancelError = True
        Commondialog1.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
        Commondialog1.ShowSave
        
       '----------------------------------------------------
       Exit Sub
       '-----------------------------
    ErrGoto:
       MsgBox "按了取消"
    End Sub
      

  6.   

    Private Sub Command1_Click()
       '打开错误处理陷阱
       On Error GoTo ErrGoto
       '----------------------------------------------------
      
        Commondialog1.CancelError = True
        Commondialog1.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
        Commondialog1.ShowSave
        MsgBox "按了确定"
       '----------------------------------------------------
       Exit Sub
       '-----------------------------
    ErrGoto:
       MsgBox "按了取消"
    End Sub
      

  7.   

    CancelError 属性返回或设置一个值,该值指示当选取“取消”按钮时是否出错。当该属性设置为 True 时,无论何时选取“取消”按钮,均产生 32755 (cdlCancel) 号错误。你可以利用On Error捕捉它。 
        另外,如果用户在“打开”、“另存为”对话框中选择“取消”按钮,Filename属性得到的是空串。