在模块里已经定义了公共变量
Public intFilenum As Integer     '文件号存储变量’
但是下面的代码运行到open的时候提示“实时错误52,错误的文件名或号码”
把 #intFilenum改成 #1可以通过,但是这里不能用1,文件很多的 
这段代码在我的别的工程里都能通过,就是这个工程不行,为什么啊?
大家帮帮忙吧!
'****输出数据按钮命令***************************************
Private Sub ComdDateOut_Click()
   If txtOutputFolder.Text = "" Then
       MsgBox "请设置输出路径", vbOKOnly, "提示"
   Else
      If Right(txtOutputFolder.Text, 1) = "\" Then
         OutName = txtOutputFolder.Text & Date & "输出.txt"
      Else
         OutName = txtOutputFolder.Text
      End If
      Open OutName For Output As #intFilenum
           DataOut ' (MngBaseFileName) '
      Close #intFilenum
      MsgBox OutName & "输出完成", vbOKOnly, "提示"
   End If
End Sub

解决方案 »

  1.   

    你的日期格式中可能有不能用于文件名的字母,改成这样试试:OutName = txtOutputFolder.Text & format(Date,"yyyy-mm-dd") & "输出.txt"要不就在open前面加
    me.caption=OutName 
    看看文件名是不是符合要求
      

  2.   

    文件号不可用被,哈哈。使用 FreeFile 函数可得到下一个可用的文件号。
    都用#1也没问题吧,你每次执行都已经把文件关闭了。
      

  3.   

    找到原因了,这句话忘写了
       intFilenum = FreeFile()   '自由文件号
      

  4.   

    还有就是对这个变量 txtOutputFolder.Text  用Dir(txtOutputFolder.Text,vbDirectory)做个判断。