Multi select macro running slowly

307Fergie

New Member
Joined
Jan 13, 2019
Messages
7
Hoping someone can help with my first attempt at a multi select macro.
The single version runs in less than a second but using this code to multi select it now takes up to 5 sec for each. Figure it is something to do with how I am getting them from the array.

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]vaFiles = Application.GetOpenFilename("Excel Files(*.csv), *.csv", _[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]             Title:="Select files", MultiSelect:=True)[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]    IfIsArray(vaFiles) Then[/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000]    For i =LBound(vaFiles) To UBound(vaFiles)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]            SetwbkToCopy = Workbooks.Open(Filename:=vaFiles(i))[/COLOR][/SIZE][/FONT]
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
There is no problem in the way of opening the files, it is the time of your machine to open each file. Put the following at the beginning of the code to see if the time improves

Code:
    vaFiles = Application.GetOpenFilename("Excel Files(*.csv), *.csv", _
             Title:="Select files", MultiSelect:=True)
    
[COLOR=#0000ff]    Application.ScreenUpdating = False[/COLOR]
    
    If IsArray(vaFiles) Then


        For i = LBound(vaFiles) To UBound(vaFiles)
                SetwbkToCopy = Workbooks.Open(Filename:=vaFiles(i))
 
Upvote 0
Thanks Dante. I do have screen updating turned off, but before the first line of code I posted. Dont think this is the problem. Cant understand why if I select a single file with this code it takes so much longer when the actual body of the macro is exactly the same.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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