Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Update 6/12/2024: Found another source of documentation

On RubberDuckVBA’s github page they do have a section that mentions each of the refactoring options:

https://github.com/rubberduck-vba/Rubberduck/wiki/Refactorings


Original article

I’m going to spend a little time today working with the refactoring features of RubberDuckVBA which is free to download here:

Downloads at rubberduckvba.com

Here is the summary page with more details about each of the RubberDuckVBA refactoring abilities, although at the time of this writing, the detailed documentation for each feature was not working:

Refactorings | rubberduckvba.com

Here is the error message I am seeing, which I have seen in the past as well:

But, let’s see if I can figure out how to use some of these features.

I’m going to use my FormAuditor project I’ve been working on using TDD to try to set up some refactorings.

First of all, I’ll need to be in the VBA IDE to see the RubberDuck menu and access the refactoring commands:

Now, you’ll notice immediately that all the refactorings in the menu are grayed out:

They are grayed out until you parse the project using RubberDuck. To do that I need to press this button:

Depending on the size of your project, and the options you’ve chosen, the pressing of this button will take time related to those things. This can make RubberDuckVBA not work very well out of the box with projects that don’t compile and / or very large projects. I have changed my settings in the past to make things a little faster for specific projects, perhaps in the future I’ll write an article on that too.

But for now, my project is small and my computer is fast, It takes RD about 3 seconds to parse my project. And now I have some options available in my menu:

So let’s try Rename, the first option.

Rename

So I just clicked on Rename and you can see from the previous screen that on the left side in the Project Explorer, the FormAuditor class was highlighted. So RubberDuck volunteers to change it’s name with this dialog into which I will type “clsFormAuditor”:

And then I hit OK. It has definitely renamed the class in the Project Explorer, but there is no other dialog. So I’ll run an MZ-Tools Find across the whole project to see if there were any other references to that elsewhere that RubberDuck updated:

So across the project, anything instantiating the class and using it was updated. I suppose if it was a variable name somewhere it would not have been updated. So let me try that and find out. I’ll put “clsFormAuditor” in a comment and as a private variable in a function somewhere and then rename the clsFormAuditor class object back to FormAuditor and see if it leaves those “unrelated” items alone.

I had a bit of a problem with what was autodetected when choosing Rename from the RubberDuck main menu, BUT, using the RubberDuck right click context menu worked like a charm:

I changed the class name back to FormAuditor and it left the variable and comment alone as I expected it to:

So that worked well. This feature can be used to only change names related to the actual object you are renaming. I’m looking forward to doing some more experiments with this and other features of the Refactoring menu in some upcoming email articles…