我可以在VBA代码中获取评论文本吗 [英] Can I get the text of the comments in the VBA code

查看:91
本文介绍了我可以在VBA代码中获取评论文本吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说以下内容:

Public Sub Information()
    'TEST
End Sub

是否有办法获得测试"? 通过VBA不知何故?

Is there a way to get "TEST" as a result? Somehow through VBA?

例如-在PHP中,有一种接受注释的好方法.这里有什么想法吗?

E.g. - In PHP there is a good way to take the comments. Any ideas here?

应该有一种方法,因为MZ-Tools之类的工具能够在生成文档时提供注释.

There should be a way, because tools like MZ-Tools are able to provide the comments when they generate the documentation.

推荐答案

经过一些测试,我得到了以下解决方案:

After some tests, I got to this solution:

只需将代码模块的名称传递给函数,它将打印所有注释行.内联评论不起作用(您必须更改条件)

simply pass the name of the code-module to the function and it will print all comment lines. Inline comments won't work(you have to change the condition)

Function findComments(moduleName As String)

Dim varLines() As String
Dim tmp As Variant

With ThisWorkbook.VBProject.VBComponents(moduleName).CodeModule

    'split the lines of code into string array
    varLines = Split(.lines(1, .CountOfLines), vbCrLf)
End With

'loop through lines in code
For Each tmp In varLines

    'if line starts with '
    If Trim(tmp) Like "'*" Then

        'print comment line
        Debug.Print Trim(tmp)
    End If
Next tmp
End Function

这篇关于我可以在VBA代码中获取评论文本吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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