打开时关闭Excel电子表格更新链接的消息

use*_*821 3 excel vba

我有一个工作簿,我想打开,没有要求更新链接,(确切的消息是:

"此工作簿包含指向其他数据源的链接.如果更新链接,Excel将尝试检索最新数据.如果您未更新链接,Excel将使用以前的信息.请注意,数据链接可用于访问未经您的许可共享机密信息,并可能执行其他有害行为.如果您不信任本工作簿的来源,请不要更新链接." )

我想要做的是通过单击Internet Explorer中的文件打开工作簿并更新链接,但不要求用户单击按钮进行更新.

我在Open Event中尝试了以下代码,但没有成功:

 Private Sub Workbook_Open()
     Application.DisplayAlerts = False
     Application.ScreenUpdating = False
 End Sub
Run Code Online (Sandbox Code Playgroud)

我也在上面的Sub中尝试了以下几行代码:

ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.FullName, Type:=xlExcelLinks
Application.ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.FullName, Type:=xlExcelLinks
Application.ActiveWorkbook.UpdateLink
Workbooks.Open ActiveWorkbook, UpdateLinks:=True
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources, Type:=xlExcelLinks
Run Code Online (Sandbox Code Playgroud)

MS Excel 2010的版本并保存为.xls文件,以便使用旧版本.

非常感谢您的帮助.提前感谢您的帮助.

尊敬,

罗伯特

use*_*821 12

为了防止将来有人帮助我,我做了以下事情:

Private Sub Workbook_Activate()
   Application.AskToUpdateLinks = False

End Sub
Run Code Online (Sandbox Code Playgroud)

这会阻止在打开文件时出现"更新链接"消息框.

罗伯特


ma_*_*YYC 5

Just to add to Robert's (@user2320821) answer -

I had to modify the code to:

Sub Workbook_Open()
   Application.DisplayAlerts = False
   Application.AskToUpdateLinks = False
   Application.DisplayAlerts = True
End Sub
Run Code Online (Sandbox Code Playgroud)

The key differences being that

1) It's a Workbook_Open sub instead of a Workbook_Activate sub. The Activate sub was not suppressing the Update Link request.

2) I had to throw in a DisplayAlerts flag toggle to suppress a second warning about the links not being updated, even after the first Update Link request was suppressed.

In case it wasn't obvious in Robert's answer, this sub worked when I put it in the ThisWorkbook object.