So I've been running this VBA code in Excel 2007 without any problems:
Sub Button_Click()
For Each objConnection In ThisWorkbook.Connections
objConnection.Refresh
Next
Dim Sheet As Worksheet, Pivot As PivotTable
For Each Sheet In ThisWorkbook.Worksheets
For Each Pivot In Sheet.PivotTables
Pivot.RefreshTable
Pivot.Update
Next
Next
MsgBox "Finished refreshing all data connections"
End Sub
Some of the people using my workbook are on Excel 2007, some are on Excel 2013.
The users on Excel 2013 are running into the following error:
Run-Time error "-2147417848 (80010108)":
Method "Refresh" of object "WorkbookConnection" failed
I've tried to replace the objConnection.Refresh
with something along the lines of ThisWorkbook.RefreshAll
but that causes Excel 2013 to crash each time its run with no errors.
All the connections have Enable Background Refresh
unchecked and the connection types are Office Data Connection and Database Query.
I can't seem to find a solution that works to refresh connections in 2010 or 2013. Any help is appreciated, thanks!