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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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