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 :crash:. 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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,099
Messages
6,170,112
Members
452,302
Latest member
TaMere

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