当另一个应用程序正在将数据写入data.txt文件并且VBA尝试读取它时,这段代码显然会引起麻烦。Excel VBA - 例外:权限被拒绝错误70
有没有办法忽略这些异常或更好的等待,直到文件可以自由访问然后继续执行代码?
fileName = "C:\TEXT\data.txt"
fileNo = FreeFile 'Get first free file number
Open fileName For Input As #fileNo
Do While Not EOF(fileNo)
Line Input #fileNo, textRow
jsonText = textData & textRow
Loop
Close #fileNo
锁定文件的其他进程是否短暂?你想等多久? –
您等待。你是程序员,进入循环直到成功。 – 2016-11-13 22:42:15
@TimWilliams这是短命的。它应该是prolly少数milisoconds。 – Totallama