vba代码重构 - 有什么工具可以协助吗? [英] vba code refactoring - are there any tools to assist?

查看:147
本文介绍了vba代码重构 - 有什么工具可以协助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重构我的VBA代码。我习惯于在基于Java的IDE中使用重构多年。 VBA编辑器是否支持任何重构,还是有任何加载项? MZ Tools没有任何这样的功能。



我想要能够至少执行以下操作:
1.重命名变量
2.拆分程序到子程序中,代码更可读
3.将变量的范围从全局更改为过程,反之亦然

解决方案


免责声明:我很忙于这个项目。







上执行。


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

解决方案

Disclaimer: I'm heavily involved with this project.


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

Version 1.2 includes an Extract Method refactoring tool:

Version 1.3 includes a Rename refactoring:

Version 2.0 (beta available, still stabilizing) includes a dozen 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, which you can follow on GitHub.

这篇关于vba代码重构 - 有什么工具可以协助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆