Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vba code refactoring - are there any tools to assist? [closed]

Tags:

excel

vba

I am trying to refactor my VBA code. I am so used to using refactoring in Java-based IDEs for a number of years. Does VBA editor support any refactoring or are there any add-ins? MZ Tools did not have any such functionality.

I want to be able to do at least the following: 1. Rename variables 2. Split Procedures into sub-procedures to make the code more readable 3. Change the scope of the variable from global to procedure and vice-versa

like image 545
Siraj Samsudeen Avatar asked Oct 04 '12 10:10

Siraj Samsudeen


People also ask

What is a refactoring tool?

Refactoring is the process of modifying programs to improve program structure without changing functionality.

Is visual studio used for refactoring the code?

Visual Studio Code supports refactoring operations (refactorings) such as Extract Method and Extract Variable to improve your code base from within your editor.

Does code refactoring improve performance?

Refactoring may lessen performance, but the change may be negligible. You need to balance the change in the maintainability of the code vs. the change in its performance.


1 Answers

Disclaimer: I'm heavily involved with this project.


Rubberduck is an open-source add-in for the VBA/VB6 IDE under [very] active development, that includes this functionality.

Version 1.3 includes a Rename refactoring:

rename refactoring

Version 2.0 (beta available, still stabilizing) includes a dozen refactorings:

Rubberduck 2.0 refactorings

  • Introduce Parameter promotes a local variable to a parameter
  • Introduce Field promotes a local variable to module scope
  • Encapsulate Field turns a public field into a property
  • Move Closer to Usage moves a field that's only used in 1 procedure, into that procedure. Or moves a local variable immediately above its first use.
  • Extract Interface lets you pick what class members to extract into an interface, creates a new class modules with stubs for them, and makes the original class implement the extracted interface.
  • Implement Interface creates stubs for all members of an unimplemented interface, so you don't need to create them manually by selecting them one by one in the code pane dropdown:

    Implements IClass1  Public Sub IClass1_DoSomething()     Err.Raise 5 'TODO implement interface member End Sub  Public Function IClass1_GetFoo() As Integer     Err.Raise 5 'TODO implement interface member End Function  Sub DoSomething()  End Sub  Function GetFoo() As Integer  End Function 

More refactoring tools are on the project's roadmap (including Extract Method), which you can follow on GitHub.

like image 136
Mathieu Guindon Avatar answered Oct 17 '22 06:10

Mathieu Guindon