Close all Modules in the VBE

Monty Norman

New Member
Joined
Mar 12, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
Hello All,

I am running into an issue that I am seeing for the first time in my Excel career.

I have a large workbook ( about 30MB) with many modules (35 of them). The workbook was developed by someone who is no longer with us. That developer did not use best practices but such is life at times.

So, the workbook takes a bit longer than usual (sometimes up to 5 minutes) to open via code and I see it open and "unfold" all these modules.
Is there a way to collapse all the modules (something like when you press the + next to the module name in the VBE) before saving the workbook?

This:
1678638033119.png


vs this:
1678638095956.png



Images are for illustration these are not the actual workbooks involved.

The code that I am using is here:
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = "C:\Users\" & Environ("username") & "\Desktop"
.InitialView = msoFileDialogViewDetails
.Filters.Add "Custom Excel Files", "*.xlsx, *.csv, *.xls, *.xls*"
.Title = "Choose the file"
.Show
End With

On Error Resume Next '/In case the User cancels the dialog.
sSelectedFile = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1)
If sSelectedFile = "" Then Exit Sub
On Error GoTo 0

Workbooks.Open Filename:=sSelectedFile
Set objSourceWrkBk = ActiveWorkbook
MsgBox "I made a refrence to this workbook: " & sSelectedFile

The Message Box is just to have an indication that the workbook was actually opened and the code continues. This will be removed after testing.

I am not sure if that is the reason why the workbook takes so long to open, I have it in the local drive, so network issues are eliminated, I have stopped all normal stuff (calculations, updating of links, screen updating and the likes) that happens when you want to speed up your code, I have code that resets the used range and clears all the empty cells, before saving, and I am not sure if the workbook is not corrupted, or, if it is, it is still being able to open and save and works as expected with no indications of trouble. This workbook is used daily and we have been using it for a while with no issues.

So that is why I think that opening these modules is the last thing to check. If you feel its might be something else, please I am all ears.

Thanks in advance!

Monty
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
FYI, this may help.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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