Could you please tell me where I should add this statement?
Thank you very much for any suggestions
Eric
Option Explicit
Public Sub Test_Menu_Item_Run()
Dim WkbkName As String
Dim wkbk As Workbook
WkbkName = "D:\documents\file1.xls"
Set wkbk = Nothing
On Error Resume Next
Activesheet.QueryTables(1).Refresh Backgroundquery:=False // Should I
add it here?
Set wkbk = Workbooks.Open(Filename:=WkbkName, UpdateLinks:=3)
On Error GoTo 0
If wkbk Is Nothing Then
MsgBox WkbkName & vbLf & "Could not be opened"
Exit Sub
End If
With wkbk
.RefreshAll
.Close savechanges:=True
End With
'get ready for the next time
WkbkName = "d:\documents\file2.xls"
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=WkbkName, UpdateLinks:=3)
Activesheet.QueryTables(1).Refresh Backgroundquery:=False // Should I
add it here?
On Error GoTo 0
If wkbk Is Nothing Then
MsgBox WkbkName & vbLf & "Could not be opened"
Exit Sub
End If
With wkbk
'if this UpdatingAll procedure is in the same workbook
'as this test_menu_item_run macro, then just use Call
Call UpdatingAll
'otherwise use
Application.Run "'Warrants Sorted Lists.xls'!UpdatingALL"
.Close savechanges:=True
End With
End Sub
Dave Peterson said:
Ahh, I think it's the .refreshall command that hasn't finished.
Is it a query that you're refreshing?
If yes, then right click on it and change the backgroundquery property to
false--so that excel will wait while the query refreshes.
You can do it in code with something like:
Activesheet.QueryTables(1).Refresh Backgroundquery:=False
(It can apply to pivottables, too.)
========
ps. Remove those .displayalert lines from the code.