如何检查直到文件存在 [英] How to check until file exist
本文介绍了如何检查直到文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以检查直到文件存在于 VBA 中.
Is there any way to check until file exists in VBA.
我想做的是让 vba 调用异步.
what I am trying to do is, making vba call asynch.
现在我跑步后
wshShell.Run """" & SFilename & """" & s
我想检查直到文件像这样存在
I want to check until file exists like this
Wait until fso.fileexists("file")
Msgbox "file is now available"
End wait!!!
vba 有什么办法吗?
is there any way in vba?
我用的是 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, ""
虽然这肯定不是最好的方法
Although this is surely not the best method
您可以使用 sleep 来代替 Application.Wait:
Instead of using Application.Wait, you can use sleep:
Sleep 1000 '1 Second
但是您需要将此添加到您的代码中才能使用它:
but you need to add this to your code to be able to use it:
#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
这篇关于如何检查直到文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文