调整VBScript以刷新目录中所有excel文件的外部数据
我有一个VBScript,用于刷新excel文件外部数据,而不实际打开它:调整VBScript以刷新目录中所有excel文件的外部数据,excel,vbscript,Excel,Vbscript,我有一个VBScript,用于刷新excel文件外部数据,而不实际打开它: Dim oExcel Set oExcel = CreateObject("Excel.Application") oExcel.Visible = True oExcel.DisplayAlerts = False oExcel.AskToUpdateLinks = False oExcel.AlertBeforeOverwriting = False Set oWorkbook = oExcel.Workboo
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
Set oWorkbook = oExcel.Workbooks.Open(FILE NAME GOES HERE)
oWorkbook.RefreshAll
oWorkbook.Save
oExcel.Quit
Set oWorkbook = Nothing
Set oExcel = Nothing
我不确定在何处或如何实现循环,因此它将刷新启动目录(即相对路径)中的所有xlsx和xls文件
Set fs = CreateObject("Scripting.FileSystemObject")
Set rootFolder = fs.GetFolder(fs.GetParentFolderName(wscript.ScriptFullName))
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oExcel.AskToUpdateLinks = False
oExcel.AlertBeforeOverwriting = False
For Each file in rootFolder.Files
If inStr(file.type, "Excel") > 0 Then
Set oWorkbook = oExcel.Workbooks.Open(file.path)
oWorkbook.RefreshAll
oWorkbook.Save
oWorkbook.Close
Set oWorkbook = Nothing
End If
Next
oExcel.Quit
Set oExcel = Nothing
你应该加上
oWorkbook.CalculateUntilAsyncQueriesDone
之后
oWorkbook.RefreshAll
然后
excel
等待所有数据更新后再保存文件请澄清您的问题。你是怎么运作的?您希望您的脚本具体做什么?运行上面的脚本时会发生什么情况?如果我将vbs文件放到目录中,当它运行时,对目录中的所有xlsx文件执行refreshall和save命令