Search code examples
pythonexcelvbaxlwings

xlwings - This workbook contains links to other data sources - display_alert doesn't work


Intention is to refresh an entire workbook with links to another workbook.
The code below results in a popup window where there is a choice between updating links or not.
Is there a way to remove this popup? Currently app.display_alerts = False doesn't work.

import xlwings as xw
app = xw.App()
app.display_alerts = False
wb = xw.Book('pathToFile')
wb.api.RefreshAll()

Solution

  • Simply set update_links=False when opening a workbook. This works for both xw.Book() as well as myapp.books.open():

    import xlwings as xw
    wb = xw.Book('pathToFile', update_links=False)
    wb.api.RefreshAll()
    

    Unless you need to open your book in a specific app, you don't need to explicitly instantiate an app object. You could also get ahold of it via wb.app, only that for this scenario, you won't need it.