129

I'm trying to write a script that opens many Excel files. I keep getting the prompt:

This workbook contains links to other data sources.

I want to keep this message from appearing, so that my script can just automatically go through all the workbooks without me having to click Don't Update for each one. Currently I'm using the following:

function getWorkbook(bkPath as string) as workbook

Application.EnableEvents=False
Application.DisplayAlerts=False
getWorkbook=Workbooks.Open(bkPath,updatelinks:=0,readonly:=false)

end function

However, the message is still appearing. How can I suppress it?

EDIT: It appears that this message is coming up for workbooks that have broken links; I wasn't seeing the This workbook contains one or more links that cannot be updated message because I'd set DisplayAlerts to false. The workbooks are linked to equivalent files in a folder on our Windows server, so when the matching file is deleted from that folder (which happens as part of our business flow), the link breaks. Is it possible to suppress the warning when the link is broken?

Also, I'm using Excel 2010.

vba_user111
  • 215
  • 1
  • 15
sigil
  • 9,370
  • 40
  • 119
  • 199
  • 1
    From the discussion with @SiddharthRout we see now the cause is different settings for different Excel versions: most likely you use Excel 2010 or later (Siddharth Rout has 2010 as well), while I'm using 2007 and see no warnings at all if links are OK. We'll perform some more investigations and get back with working solution - I hope so) Now try Siddharth Rout's answer. – Peter L. Feb 16 '13 at 10:55
  • 2
    My upvote for very interesting case! – Peter L. Feb 16 '13 at 10:56
  • @PeterL. since you are not getting the update links even when you open the file manually, I guess there is a setting which I am missing somewhere. Let me test it in Excel 2007 before I can confirm. :) – Siddharth Rout Feb 16 '13 at 11:02
  • Can you post a sample of a problem file? It would be good to see the nature of the links – brettdj Feb 16 '13 at 11:25
  • @brettdj, it's proprietary so I can't post a whole file. I will investigate the links so I can see if there's some problem with them. – sigil Feb 16 '13 at 17:26
  • @sigil please find the updated answer for all the options tested for Excel 2010. – Peter L. Feb 17 '13 at 10:21

9 Answers9

158

UPDATE:

After all the details summarized and discussed, I spent 2 fair hours in checking the options, and this update is to dot all is.

Preparations

First of all, I performed a clean Office 2010 x86 install on Clean Win7 SP1 Ultimate x64 virtual machine powered by VMWare (this is usual routine for my everyday testing tasks, so I have many of them deployed).

Then, I changed only the following Excel options (i.e. all the other are left as is after installation):

  • Advanced > General > Ask to update automatic links checked:

Ask to update automatic links

  • Trust Center > Trust Center Settings... > External Content > Enable All... (although that one that relates to Data Connections is most likely not important for the case):

External Content

Preconditions

I prepared and placed to C:\ a workbook exactly as per @Siddharth Rout suggestions in his updated answer (shared for your convenience): https://www.dropbox.com/s/mv88vyc27eljqaq/Book1withLinkToBook2.xlsx Linked book was then deleted so that link in the shared book is unavailable (for sure).

Manual Opening

The above shared file shows on opening (having the above listed Excel options) 2 warnings - in the order of appearance:

WARNING #1

This workbook contains links to other data sources

After click on Update I expectedly got another:

WARNING #2

This workbook contains one or more links that cannot be updated

So, I suppose my testing environment is now pretty much similar to OP's) So far so good, we finally go to

VBA Opening

Now I'll try all possible options step by step to make the picture clear. I'll share only relevant lines of code for simplicity (complete sample file with code will be shared in the end).

1. Simple Application.Workbooks.Open

Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx"

No surprise - this produces BOTH warnings, as for manual opening above.

2. Application.DisplayAlerts = False

Application.DisplayAlerts = False
Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx"
Application.DisplayAlerts = True

This code ends up with WARNING #1, and either option clicked (Update / Don't Update) produces NO further warnings, i.e. Application.DisplayAlerts = False suppresses WARNING #2.

3. Application.AskToUpdateLinks = False

Application.AskToUpdateLinks = False
Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx"
Application.AskToUpdateLinks = True

Opposite to DisplayAlerts, this code ends up with WARNING #2 only, i.e. Application.AskToUpdateLinks = False suppresses WARNING #1.

4. Double False

Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx"
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True

Apparently, this code ends up with suppressing BOTH WARNINGS.

5. UpdateLinks:=False

Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx", UpdateLinks:=False

Finally, this 1-line solution (originally proposed by @brettdj) works the same way as Double False: NO WARNINGS are shown!

Conclusions

Except a good testing practice and very important solved case (I may face such issues everyday while sending my workbooks to 3rd party, and now I'm prepared), 2 more things learned:

  1. Excel options DO matter, regardless of version - especially when we come to VBA solutions.
  2. Every trouble has short and elegant solution - together with not obvious and complicated one. Just one more proof for that!)

Thanks very much to everyone who contributed to the solution, and especially OP who raised the question. Hope my investigations and thoroughly described testing steps were helpful not only for me)

Sample file with the above code samples is shared (many lines are commented deliberately): https://www.dropbox.com/s/9bwu6pn8fcogby7/NoWarningsOpen.xlsm

Original answer (tested for Excel 2007 with certain options):

This code works fine for me - it loops through ALL Excel files specified using wildcards in the InputFolder:

Sub WorkbookOpening2007()

Dim InputFolder As String
Dim LoopFileNameExt As String

InputFolder = "D:\DOCUMENTS\" 'Trailing "\" is required!

LoopFileNameExt = Dir(InputFolder & "*.xls?")
Do While LoopFileNameExt <> ""

Application.DisplayAlerts = False
Application.Workbooks.Open (InputFolder & LoopFileNameExt)
Application.DisplayAlerts = True

LoopFileNameExt = Dir
Loop

End Sub

I tried it with books with unavailable external links - no warnings.

Sample file: https://www.dropbox.com/s/9bwu6pn8fcogby7/NoWarningsOpen.xlsm

Liam
  • 27,717
  • 28
  • 128
  • 190
Peter L.
  • 7,276
  • 5
  • 34
  • 53
  • 6
    `Application.DisplayAlerts = False` will not disable those warnings :) – Siddharth Rout Feb 16 '13 at 08:58
  • @SiddharthRout Sid I swear I don't see them: I have a file with such links and see the warning while open it manually. With the above script - no warnings) May share video for you))) Excel 2007 - just in case. – Peter L. Feb 16 '13 at 09:00
  • Ok try this :) Open two new workbooks. Save them as book1.xlsx and book2.xlsx. In Cell A1 of book1, type "=" and point it to cell A1 of Book2. Type something in cell A1 of Book2 if you wish and then close both the workbooks. Now open book1 using your code and you will see that you still get the prompt :) – Siddharth Rout Feb 16 '13 at 09:03
  • Also before you run the above excercise, check `?Application.AskToUpdateLinks` in the Immediate window. Is it already set to false or is it true... – Siddharth Rout Feb 16 '13 at 09:04
  • @SiddharthRout here is what I see in Immediate window: http://floomby.ru/s1/waUUwT – Peter L. Feb 16 '13 at 09:08
  • @SiddharthRout No warnings. Shall I screen the video?) – Peter L. Feb 16 '13 at 09:10
  • @brettdj thanks! that's how I earn my modest living - producing clear and thorough testing reports. In any case, this page is in my bookmarks forever: for the options given it does the job, and hopefully will save some time for future seekers)) – Peter L. Feb 17 '13 at 11:11
  • 2
    +1 to brettdj. Your customers must be happy if all your reports are similar) – Ksenia Feb 17 '13 at 17:18
  • @PeterL., all the workbooks I'm dealing with have their Security Settings set to `Prompt user on automatic update for Workbook Links.` I have tried all these combinations and none of them have worked. The only thing that has worked is the AutoIt solution I posted below. Are you able to suppress the warnings when `Prompt user...` is set? – sigil Feb 18 '13 at 01:04
  • @sigil `Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx", UpdateLinks:=False` works fine for me for the active option you specified - I see no warnings. It seems that you have some other options that may interfere with that one, but I have no idea what they could be... – Peter L. Feb 18 '13 at 09:45
  • watch out, your excel seems torn – Aki Apr 27 '15 at 06:51
  • +1 Fantastic answer. Thank you! I used this with the Python win32com bindings and it worked. win32com.client.gencache.EnsureDispatch ("Excel.Application").Workbooks.Open(filename, UpdateLinks = False) – bsg Jul 01 '16 at 12:45
  • @bsg you're welcome! Yeah, that was a great piece of research... and the way I earn my modest living :) – Peter L. Jul 10 '16 at 07:57
29

Open the VBA Editor of Excel and type this in the Immediate Window (See Screenshot)

Application.AskToUpdateLinks = False 

Close Excel and then open your File. It will not prompt you again. Remember to reset it when you close the workbook else it will not work for other workbooks as well.

ScreenShot:

enter image description here

EDIT

So applying it to your code, your code will look like this

Function getWorkbook(bkPath As String) As Workbook
    Application.AskToUpdateLinks = False
    Set getWorkbook = Workbooks.Open(bkPath, False)
    Application.AskToUpdateLinks = True
End Function

FOLLOWUP

Sigil, The code below works on files with broken links as well. Here is my test code.

Test Conditions

  1. Create 2 new files. Name them Sample1.xlsx and Sample2.xlsx and save them on C:\
  2. In cell A1 of Sample1.xlsx, type this formula ='C:\[Sample2.xlsx]Sheet1'!$A$1
  3. Save and close both the files
  4. Delete Sample2.xlsx!!!
  5. Open a New workbook and it's module paste this code and run Sample. You will notice that you will not get a prompt.

Code

Option Explicit

Sub Sample()
    getWorkbook "c:\Sample1.xlsx"
End Sub

Function getWorkbook(bkPath As String) As Workbook
    Application.AskToUpdateLinks = False
    Set getWorkbook = Workbooks.Open(bkPath, False)
    Application.AskToUpdateLinks = True
End Function
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • 3
    That code worked for me Sid (*in xl2010*) in that it disabled the message, but it did update the link in the background. Using ` Set getWorkbook = Workbooks.Open(bkPath, False)` will suppress the warning, and not drive the update. Onto testing *xl03* and *xl10* – brettdj Feb 16 '13 at 11:40
  • 1
    Thanks Dave. :) BTW, I guess you meant xl03 and xl2007 :P Also I edited the above post to reflect your suggestion. – Siddharth Rout Feb 16 '13 at 11:52
  • 1
    @brettdj thanks very much! We spent a good hour with Sid that morning trying to figure out the case. So, will the above code suppress all warnings for any Excel version and makes links **updated** silently? And how should I modify the code to AVOID update? Sorry, I'm a bit lost in options, but hope I explained all correctly) – Peter L. Feb 16 '13 at 12:17
  • @brettdj and what will be if `Application.DisplayAlerts = False` is added as well? – Peter L. Feb 16 '13 at 12:19
  • @brettdj I'm using xl2010. Adding `Application.AskToUpdateLinks=False` does not suppress the warning either, whether I use it alone or in conjunction with `Application.DisplayAlerts=False` and `Workbooks.Open(bkPath, False)`. I'll check to see if the workbook has broken links, if that makes a difference. – sigil Feb 16 '13 at 17:24
  • @SiddharthRout I discovered that all the links that this is happening for are broken links (see my edit to original post). Is there something that can be done in this situation? – sigil Feb 16 '13 at 17:38
  • @sigil and Sid - in case links are broken (which is not surprise for me, since today I spent about 2 hours testing all the possible combinations of both Excel & VBA settings), I think I have a solution that may help with one option not yet listed here. Please just be patient - it's about midnight in my place, and I got a bit tired looking for the solution of that challenge. Will get back tomorrow with any result - either working or not. – Peter L. Feb 16 '13 at 21:02
  • @sigil: Please see Followup in the post above. – Siddharth Rout Feb 17 '13 at 03:55
  • @SiddharthRout, I already tried using the `.AskToUpdateLinks=False` solution and that didn't work, see my comment to brettdj above. – sigil Feb 18 '13 at 01:00
  • 1
    @sigil: Without seeing your workbook, i won't be able to comment further. I have tested my code with different conditions and it works flawlessly. In fact it is the right way to suppress those alerts... – Siddharth Rout Feb 18 '13 at 03:52
9

Excel 2016 I had a similar problem when I created a workbook/file and then I changed the names but somehow the old workbook name was kept. After a lot of googling... well, didn't find any final answer there...

Go to DATA -> Edit Link -> Startup Prompt (at the bottom) Then choose the best option for you.

user2060451
  • 2,576
  • 3
  • 24
  • 31
  • 4
    This is the best solution. It only affects the workbook for which this choice is made and it doesn't require any VBA. – Gaia Sep 23 '16 at 13:50
9

(I don't have enough rep points to add a comment, but I want to add some clarity on the answers here)

Application.AskToUpdateLinks = False is probably not what you want.

If set to False, then MS Excel will attempt to update the links automatically it just won't prompt the user beforehand, sorta counter-intuitive.

The correct solution, if you're looking to open a file without updating links should be:

Workbook.Open(UpdateLinks:=0)

Related link: Difference in AskToUpdateLinks=False and UpdateLinks:=0

Donaldo Almazan
  • 121
  • 1
  • 5
5

I wanted to suppress the prompt that asks if you wish to update links to another workbook when my workbook is manually opened in Excel (as opposed to opening it programmatically via VBA). I tried including: Application.AskToUpdateLinks = False as the first line in my Auto_Open() macro but that didn't work. I discovered however that if you put it instead in the Workbook_Open() function in the ThisWorkbook module, it works brilliantly - the dialog is suppressed but the update still occurs silently in the background.

 Private Sub Workbook_Open()
    ' Suppress dialog & update automatically without asking
    Application.AskToUpdateLinks = False
End Sub
Jesse
  • 8,605
  • 7
  • 47
  • 57
  • Good idea; unfortunately, this project required that I open a set of workbooks whose contents I couldn't modify. So there would be no way to set the `Workbook_Open()` event for each of the workbooks in my target set. – sigil May 17 '13 at 20:00
2

I've found a temporary solution that will at least let me process this job. I wrote a short AutoIt script that waits for the "Update Links" window to appear, then clicks the "Don't Update" button. Code is as follows:

while 1
if winexists("Microsoft Excel","This workbook contains links to other data sources.") Then
   controlclick("Microsoft Excel","This workbook contains links to other data sources.",2)
EndIf
WEnd

So far this seems to be working. I'd really like to find a solution that's entirely VBA, however, so that I can make this a standalone application.

sigil
  • 9,370
  • 40
  • 119
  • 199
2

Hope to give some extra input in solving this question (or part of it).

This will work for opening an Excel file from another. A line of code from Mr. Peter L., for the change, use the following:

Application.Workbooks.Open Filename:="C:\Book1withLinkToBook2.xlsx", UpdateLinks:=3

This is in MSDS. The effect is that it just updates everything (yes, everything) with no warning. This can also be checked if you record a macro.

In MSDS, it refers this to MS EXCEL 2010 and 2013. I'm thinking that MS EXCEL 2016 has this covered as well.

I have MS EXCEL 2013, and have a situation pretty much the same as this topic. So I have a file (call it A) with Workbook_Open event code that always get's stuck on the update links prompt. I have another file (call it B) connected to this one, and Pivot Tables force me to open the file A so that the data model can be loaded. Since I want to open the A file silently in the background, I just use the line that I wrote above, with a Windows("A.xlsx").visible = false, and, apart from a bigger loading time, I open the A file from the B file with no problems or warnings, and fully updated.

KernelPanic
  • 2,328
  • 7
  • 47
  • 90
JDF
  • 129
  • 1
  • 12
0

To suppress these warnings, you can use a combination of AskToUpdateLinks and DisplayAlerts.

    Application.AskToUpdateLinks = False
    Application.DisplayAlerts = False
claudius
  • 747
  • 1
  • 10
  • 24
-1

Just as a caveat to this conversation. To remove the update links notification you could do something like this inside workbook_open().

Private Sub workbook_Open()
Application.ThisWorkbook.UpdateLinks = xlUpdateLinksNever 
#Your code goes here
Application.ThisWorkbook.UpdateLinks = xlUpdateLinksAlways
End Sub
paynod
  • 19
  • 1
  • 7