vba - 如何检查直到文件存在

标签 vba ms-word

有没有办法检查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/

相关文章:

java - 如何使用 Apache-POI api for java (MS-Word) 在后续页面上重复 XWPFTable header

c# - 需要有关如何从 .docx/.doc 文件中提取数据然后将数据提取到 SQL Server 中的建议

excel - GetPivotData #REF 错误,数据格式问题?

excel - 如何在Access数据库中使用左连接从Excel表中进行选择 - EXCEL VBA

excel - 在邮件正文中插入文本、超链接和表格

date - 如何在 MS Word 字段中显示上个月?

php - 使用 PHP 从 doc、xls 文件中读取数据

excel - 在 VBA 中创建类的实例的函数

excel - 我可以转换为任何对象的默认接口(interface)吗?

c# - 如何获取 Word 应用程序的 Hwnd/进程 ID,并将其设置为前景窗口