有没有办法检查VBA中文件是否存在。
我想做的是,让 vba 调用异步。
现在我运行后
wshShell.Run """" & SFilename & """" & s
我想检查直到文件像这样存在
Wait until fso.fileexists("file")
Msgbox "file is now available"
End wait!!!
vba有什么办法吗?
我正在使用word vba。
最佳答案
你可以这样做:
Do
If fso.FileExists("file") Then
Exit Do
End If
DoEvents 'Prevents Excel from being unresponsive
Application.Wait Now + TimeValue("0:00:01") 'wait for one second
Loop
MsgBox "file available", vbOKOnly, ""
虽然这肯定不是最好的方法
您可以使用 sleep 来代替 Application.Wait:
Sleep 1000 '1 Second
但是您需要将其添加到您的代码中才能使用它:
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds as Long) 'For 32 Bit Systems
#End If
关于vba - 如何检查直到文件存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37065764/