在Excel中刷新并保存为文本文件

我一直试图自动刷新我的表(通过电力查询从SQL数据库获得),并直接保存为文本文件(制表符分隔)我是非常新的VBA和我使用的macros是

Public Sub UpdatePowerQueries() 'Macro to update the Power Query script(s) and save the file as .txt Dim cn As WorkbookConnection For Each cn In ThisWorkbook.Connections If Left(cn, 13) = "Power Query -" Then cn.Refresh Next cn Application.DisplayAlerts = False ActiveSheet.SaveAs Filename:="customfile" & Format(Date, "yyyymmdd") & ".txt", FileFormat:=xlTextWindows Application.DisplayAlerts = True End Sub 

现在我面对的问题是刷新部分和保存部分自己工作正常,但如果我把它们放在同一个macros中,保存部分发生得太快,文本文件是空的。 谁能帮我 ?

谢谢

Personnaly,我select有点耐心,并添加了一个计时器几秒钟后继续!

尝试添加这之间:

 DoEvents Application.Wait (Now + TimeValue("0:00:05")) DoEvents