VBA code to wait until refresh is over- Help needed

Mallappa

New Member
Joined
Jul 20, 2012
Messages
15
Hi Friends,

I am new to VBA and stuck here in the below code. Actually I have bunch of excel files in a particular folder which I need to open individually and Refresh all, Save and close. I found some code in net but the problem is code is not allowing excel to finish refresh completely so I am getting result as N/A. I want a VBA code to wait until refresh is done before it execute the next step. I went through few of the posts here but most suggestions are on "Unticking Enable Background Refresh". But in my case the option is ticked by default, wrost thing is I cant untick it :oops:. Any other help on this is hilgly appreciated.

The code I am using is as below.

Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook

folderPath = "C:\Test\" 'change to suit

If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

filename = Dir(folderPath & "*.xls")
Do While filename <> ""
Set wb = Workbooks.Open(folderPath & filename)
Sheets("Control").Select
ActiveWorkbook.RefreshAll
Application.ScreenUpdating = False
Sheets("Slide").Select
ActiveWorkbook.Save
ActiveWindow.Close
filename = Dir
Loop
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,972
Messages
6,128,014
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top