vba 打开时关闭 Excel 电子表格的更新链接的消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23158276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Turn Off Msg for Update Links for Excel Spreadsheet upon Opening
提问by user2320821
I have a workbook that I would like to open and not have it ask to update links, (exact message is :
我有一个工作簿,我想打开它,但没有要求更新链接(确切消息是:
"This workbook contains links to other data sources. If you update the links, Excel will attempt to retrieve the latest data. If you odon't update the links, Excel will use the previous information. Note that data links can be used to access and share confidential information without your permission and possibly perform other harmful acts. Do not update the links if you do not trust the source of this workbook." )
"此工作簿包含指向其他数据源的链接。如果您更新链接,Excel 将尝试检索最新数据。如果您不更新链接,Excel 将使用以前的信息。请注意,数据链接可用于访问未经您的许可共享机密信息,并可能执行其他有害行为。如果您不信任此工作簿的来源,请不要更新链接。” )
What I would like to do is open the workbook by clicking on the file in Internet Explorer and have the links update but not ask for the user to click the button to update.
我想要做的是通过单击 Internet Explorer 中的文件打开工作簿并更新链接,但不要求用户单击按钮进行更新。
I have tried the following code in the Open Event for the work book with not success:
我在工作簿的打开事件中尝试了以下代码,但没有成功:
Private Sub Workbook_Open()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
End Sub
I have also tried the following lines of code in the above Sub:
我还在上面的 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
The version of MS Excel 2010 and saving to an .xls file for sake of those with legacy versions.
MS Excel 2010 的版本并保存为 .xls 文件,以便使用旧版本。
Your help would be very appreciated. Thank you in advance for all your help.
您的帮助将不胜感激。预先感谢您的帮助。
Respectfully,
尊敬,
Robert
罗伯特
回答by user2320821
Just in case this might help anyone in the future the following is what I did:
以防万一这可能对将来的任何人有所帮助,以下是我所做的:
Private Sub Workbook_Activate()
Application.AskToUpdateLinks = False
End Sub
This prevented the Update Links message box from appearing when the file is opened.
这可以防止在打开文件时出现更新链接消息框。
Robert
罗伯特
回答by ma_YYC
Just to add to Robert's (@user2320821) answer -
只是添加到罗伯特 (@user2320821) 的答案中 -
I had to modify the code to:
我不得不将代码修改为:
Sub Workbook_Open()
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Application.DisplayAlerts = True
End Sub
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.
1) 它是 Workbook_Open 子而不是 Workbook_Activate 子。Activate sub 没有抑制更新链接请求。
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.
2)我不得不投入一个 DisplayAlerts 标志切换来抑制关于未更新链接的第二个警告,即使在第一个更新链接请求被抑制之后也是如此。
In case it wasn't obvious in Robert's answer, this sub worked when I put it in the ThisWorkbook object.
以防罗伯特的回答不明显,当我把它放在 ThisWorkbook 对象中时,这个子工作。
回答by fixform
I'm using this code in my vba .xlm file..
我在我的 vba .xlm 文件中使用此代码..
Private Sub Workbook_Open()
ThisWorkbook.UpdateLinks = xlUpdateLinksNever
End Sub
M Office2013
M Office2013