Workbooks created and stored in dictionary - slow processing

Jgiordano

New Member
Joined
Nov 22, 2013
Messages
8
So here my code. Basically, it creates around 80 workbooks and keep it opened in memory for further purpose. I use a dictionary to be able to loop in those workbooks to distribute reports and then loop again to save them all once the report process is done. I posted only the workbooks creation part, and it takes forever to execute !

Code:
For Each nom In Range("nomgestionnaire")
    If nom.Value <> "" Then
        Set book = Workbooks.Add()
        book.Windows(1).Visible = False
        Classeurs.Add nom.Value, book
        
        'Delete all other sheets except Sheet1
        Application.DisplayAlerts = False
        On Error Resume Next
        For Each sh In book.Worksheets
            If sh.Name <> "Sheet1" Or sh.Name <> "Feuil1" Then
                sh.Delete
            End If
        Next
        
        Application.DisplayAlerts = True
    End If

Next


This code is pretty simple that's why i wonder why it takes so long to execute.

Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You could get rid of the part deleting sheets if you created single sheet workbooks with this.
Code:
Set book = Workbooks.Add(xlWBATWorksheet)

By the way, why are you addding the workbooks to a dictionary?
 
Upvote 0
Thanks for that tip ! i will modify it.
Honestly, I use dictionary because i find it easier to use than collections and that i don't know other way to list workbooks and refer to it easily.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

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