各位大哥,我用comdlg控件作保存之用,屡次失败,代码如下,请指正!
With CommonDialog2
       .CancelError = False
       .MaxFileSize = 32767
       .Flags = cdlOFNReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
       .DialogTitle = "保存文件"
       .Filter = "所有文件类型(*.txt)|*.txt"
       .FileName = App.Path & "\abc.txt"
       .ShowSave
    End With
点击按钮保存,但是到目标地点一看,还是没有根本没保存,不知道咋回事。请大家指点一下好吗。

解决方案 »

  1.   

    Private Sub Command1_Click()
     CommonDialog1.ShowSave
      Open CommonDialog1.FileName For Output As #1
       Print #1, "数据已写入...."
       Close #1
    End SubPrivate Sub Form_Load()
    CommonDialog1.Flags = cdlOFNReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
    CommonDialog1.FileName = App.Path & "\abc.txt"
    CommonDialog1.Filter = "所有文件类型(*.txt)|*.txt"
    End Sub
      

  2.   

    我想应该不用指定filename的值吧,能给个保存文件的完整代码么
      

  3.   

    FileName 是自己选择的文件名,1楼给的是默认名,你只管选择别的文本文件即可With CommonDialog2
           .CancelError = False
           .MaxFileSize = 32767
           .Flags = cdlOFNReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
           .DialogTitle = "保存文件"
           .Filter = "所有文件类型(*.txt)|*.txt"
           .FileName = App.Path & "\abc.txt"
           .ShowSave
        End With
      Open CommonDialog1.FileName For Output As #1
       Print #1, "数据已写入...."
       Close #1
      

  4.   

    概念错误。
    ShowSave 只是用来选择保存文件的路径和文件名,文件数据的写入(保存)需要程序实现。
      

  5.   

    cdlg控件只是用于得到用户选择的文件(注意不是文件夹!!!)一个可视化界面(GUIDE)而已!