我有一个 tool.xlsx 文件,它使用外部数据连接到 Access DB(两者都在网络驱动器上,可供具有适当访问权限的用户使用)。我有一个刷新该工作簿中所有连接的 vbscript(下面的代码)。当我运行这个脚本时,一切都像魅力一样工作,但是当同事运行它时,它不会抛出任何错误,但并非所有连接都被刷新。有任何想法吗?
Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = false
xlapp.workbooks.open "\\networkpath\tool.xlsx"
xlapp.displayalerts = false
set wr = xlapp.workbooks.Open("\\networkpath\tool.xlsx")
wr.refreshall
xlapp.visible = false
wr.Save
wr.Close
这是来自该 tool.xlsx 工作簿的连接字符串:
Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=\\networkpath\db.accdb;Mode=Share Deny Write;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False
这是一次刷新每个连接的不同方法:
on error resume next
Dim XLApp
Dim XLWkb
Set XLApp = CreateObject("Excel.Application")
xlapp.visible = false
xlapp.displayalerts = false
set wr = xlapp.workbooks.open("\\networkpath\tool.xlsx")
for each Cn in wr.Connections
Cn.Refresh
next
wr.refreshall
xlapp.visible = false
wr.Save
wr.Close