Skip to content

Excel VBA class that bundles stuff to "speed up" VBA code execution.

License

Notifications You must be signed in to change notification settings

VBA-tools2/XLSpeedUp.vba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XLSpeedUp.vba

Excel VBA class that bundles stuff to "speed up" VBA code execution.

This is essentially a republish of Brian Satola’s class which can be found at https://chejunkie.com/knowledge-base/speed-up-class-excel-vba/. So all credits go to him!

The main reason for this repository is to increase its visibility.

Features

Bundle some common tricks to speed up VBA code execution. These mainly are

  • turn off worksheet calculation

  • turn off screen updating

  • ignore events

Prerequisites / Dependencies

Since this is an Excel VBA class you obviously need Microsoft Excel.

How to install / Getting started

Add the file(s) from the src folder to your project. Yes, it’s that simple.

If you need some more advice on how to do that, expand me.
  1. Open Microsoft Excel.

  2. Open the Visual Basic Editor (VBE) (Alt+F11).

  3. Add the file(s) in the src folder to your VBA project.

    • With Rubberduck:

      1. Right-click on the project to which you want to add the file(s) in the “Code Explorer” (to show it press Ctrl+R) and click on Add  Existing Files…​.

      2. Select all files in the src folder and click on Open.

    • Without Rubberduck:

      1. Select all files in the src folder in Windows File Explorer.

      2. Drag-and-drop them to the corresponding project in VBE’s “Project Explorer”.
        (To show it press Ctrl+R. Hit it twice if the Code Explorer shows up first.)

  4. Check, if there are obvious errors by compiling the project (Debug  Compile ‹project name›).

  5. Save the file/project.

    1. Be sure that the file/project you want to save is “active” in the VBE by checking, if its name is shown in VBE’s title bar.
      (If it’s not, open a (class) module of the corresponding project (and close it again).)

    2. Press the “Save” button (the disc symbol similar to 💾) in VBE’s toolbar.

    3. Check that the file (really) was saved by having a look at the “last modified date” of the (project) file in the Windows File Explorer.

Usage / Show it in action

A most basic example is

Public Sub DoSomething()
    Dim SpeedUp As XLSpeedUp
    Set SpeedUp = New XLSpeedUp
    SpeedUp.TurnOn

    'do something

    SpeedUp.TurnOff
End Sub

You can also have a look in the demo folder for a full (dummy) example.

Running Tests

Yes, Unit Tests in Excel are possible. For that you need to have the awesome Rubberduck AddIn installed (and enabled).

The procedure is very similar to the one given in the How to install / Getting started section, but this time add the files from the tests folder (instead of the files from the src folder). When you are done with that, additionally perform the following steps.

  1. Check that the files from the src folder are present in the project as well or that you have a reference to project with the source files.[1]
    (Otherwise tests will/should fail.)

  2. Add a reference to the “Rubberduck AddIn” to the project (with the test modules).

    If you don’t have a clue how to do that, expand me.
    • With Rubberduck:

      1. Right-click somewhere on the project in the “Code Explorer” and click on Add/Remove References…​.

      2. Add the reference.

        1. Type (parts of) the library name in the search box until you see it in below (left) list or it is empty.

          • If the AddIn file name is in the lower left list box:

            1. Select the library in the (left) list and

            2. click on the button to add it to the project references.

          • If the the AddIn file name is not in the list:

            1. Click on the Browse…​ button.

            2. Browse to the folder where the AddIn is located.

            3. Select the AddIn and

            4. press the Open button.

      3. Click on the OK button to close the window.

    • Without Rubberduck:

      1. Open the Reference manager in the VBE (Tools  References…​).

        • If the AddIn project name is in the list of available references:

          1. Add a checkmark to the corresponding library.

        • If it’s not in the list:

          1. Click on the Browse…​ button.

          2. Browse to the folder where the AddIn is located.

          3. Select the AddIn and

          4. press the Open button.

      2. Click on the OK button to close the window.

      3. Save the file/project.

  3. Open the “Test Explorer” (Rubberduck  Unit Tests  Test Explorer).

  4. Run the tests by clicking Run  All Tests.

Used By

This project is used by (at least) these projects:

If you know more, we will be happy to add them here. In addition it is used by a lot of private, i.e. non-public, Excel AddIns created by the authors.

Known issues and limitations

None that we are aware of.

Contributing

All contributions are highly welcome!!

If you are new to git/GitHub, please have a look at https://github.com/firstcontributions/first-contributions where you will find a lot of useful information for beginners.

We recently were pointed to https://www.conventionalcommits.org which sounds very promising. We will use them from now on too (and hopefully don’t forget it in a hurry).

Further Reading

Here is a collection of (useful) links that deal with writing efficient/performant code:

If you know other great sources for this topic, please let us know and we’ll be happy to extend the list.

FAQ

  1. What are the '@... comments good for in the code?

    You should really have a look at the awesome Rubberduck project!

Similar Projects

None that we are aware of.

But if you know some, please let me know. Maybe we can combine forces.

License

MIT


1. See the collapsible in the next point on how to do that. If you use the Rubberduck way, before adding the reference you first need to switch to the Projects tab.

About

Excel VBA class that bundles stuff to "speed up" VBA code execution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages