无法打开文件在Excel VBA中,运行时错误“52”
问题描述:
所以我有了这个代码无法打开文件在Excel VBA中,运行时错误“52”
Dim fpath As String
fpath = "D:\stats.csv"
Open fpath For Append As #fw
然而,当我试图运行它,我得到一个运行时错误“ 52':错误的文件名或编号。
我不知道我在做什么错,也许这是我不知道的Office 2016/Windows 10毛刺。
在此先感谢您的帮助
答
你需要fw
是一个有效文件标识号。为此,从函数FreeFile
获取标识符:
Dim fpath As String, fw As Long
fw = FreeFile ' <--------- get a valid file identifier
fpath = "D:\stats.csv"
Open fpath For Append As #fw