VBA hangs when opening excel file

cwunderlich

Board Regular
Joined
Sep 24, 2010
Messages
101
I have a macro which loops through a list of excel filepaths. The macro will read each path, open the workbook, copy/pull various data out of each workbook and then pastevalues the data into a central workbook. There are about 2000 filepaths it will need to loop through. So as you can see, it is a pretty simple macro. It runs just fine.

However, after running for a while (maybe after it has loop thru the first 70 or so filepaths), excel keeps hanging up on me (it shows the "Downloading" message box that you get when opening a file). If I click cancel on the msg box, the workbook still opens and the macro continues as normal. But with these "Downloading" message boxes constantly popping up, I would have to sit here and babysit the macro for 1000s of more filepaths. Does anyone know why excel gets stuck here? And is there a way around it?

What is even weirder is that this hanging message box does not happen on every Workbooks.Open instance, it just happens after every few.

here is an example of the code I am using:

Code:
With ThisWorkbook.Sheets("Filepaths")
           For i = firstrow To lastrow
                   SourceFile = .Cells(i, 1).Value
                   Workbooks.Open SourceFile, ReadOnly:=True 
                   Set MyFile = Workbooks(Workbooks.Count)
                   ..more code..........
                   ..more code..........
                   ..more code..........
                    MyFile.close
           Next i
End With
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,373
Messages
6,124,545
Members
449,169
Latest member
mm424

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