Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调整VBScript以刷新目录中所有excel文件的外部数据_Excel_Vbscript - Fatal编程技术网

调整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

我有一个VBScript,用于刷新excel文件外部数据,而不实际打开它:

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命令