VBA写入文本文件: Run-time error 52 'bad file name or number'

标签 vba

Public Sub EdgeColor_Click()
    Dim intInFile As Integer
    intInFile = FreeFile

    Open "c:\picturename.csv" For Output As #intFileNo
    Print #intFileNo, "test"

    Close #intFileNo
End Sub

这是我的代码,我收到运行时错误 52 'bad file name or number'。我尝试过作为输入并使文件存在,但我得到了同样的错误。

这是 Proficy iFix 图形中的 VBA,我终生无法弄清楚我做错了什么。

最佳答案

你混淆了 intInFileintFileNo

如果您不使用 option explicit 命令,则可能将 intFileNo 简单地设置为零,这可能会解释无效数字。

这个小命令出现在我的 VB/VBA 文件每个的顶部,因为我之前已经被这个烧伤了很多次了。

关于VBA写入文本文件: Run-time error 52 'bad file name or number' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6301495/

相关文章:

vba - 宏返回#REF!在excel中

database - Windows Vista 上的 MSDataShape

arrays - VBA 第一个数组项始终为空

excel - VBA 中的 Range.Formula 不接受输入范围

VBA 获取本月的最后一天

excel - 在 VBA Excel 上遇到 XML 阶段问题

database - 使用来自单独数据库的 VBA 代码关闭数据库

excel - Office 2013 Excel .PutInClipboard 不同吗?

vba - 找不到Excel VBA公式类型不匹配错误

sql - 将vba变量日期传递给sql语句