首页 > 解决方案 > 你知道如何在 VBA 代码中标记行吗?

问题描述

我想区分我的 VBA 代码中的行,尤其是对命令。我尝试将它们级联起来,但是尽管我努力了,但有时我会迷失哪对代码属于/在哪里结束,当我在其他循环中有更多循环时。有没有办法用颜色标记线条?所以我可以通过颜色区分对命令?

谢谢你。

杰克

标签: excelvba

解决方案


不幸的是,VBA 编辑器中没有匹配if和结束endif的功能。我使用 Rubberduck,一个免费的 VBA 插件。有了它,您可以轻松缩进代码并使其更具可读性。

前:

Option Explicit

Function test(a As Integer)
Dim b As Integer

    b = 1
     If a > 1 Then
   b = 2
    If a > 21 Then
b = 3
Else
b = 4
    End If
       End If
    test = b
End Function

经Rubberduck处理后:

Option Explicit

Function test(a As Integer)
    Dim b As Integer

    b = 1
    If a > 1 Then
        b = 2
        If a > 21 Then
            b = 3
        Else
            b = 4
        End If
    End If
    test = b
End Function

它还可以做更多的事情。你可以在这里下载:http ://rubberduckvba.com/


推荐阅读