VBA:有没有一种方法来获取/读取模块属性?

时间:2020-01-14 11:50:25

标签: excel vba ms-word

在Visual Basic for Applications(VBA)中,可以使用Attribute关键字设置模块或变量的属性。例如

    ' Header
Attribute VB_Name = "ClassOrModuleName"
Attribute VB_GlobalNameSpace = False ' ignored
Attribute VB_Creatable = False ' ignored
Attribute VB_PredeclaredId = False ' a Value of True creates a default global instance
Attribute VB_Exposed = True ' Controls how the class can be instanced.

'Module Scoped Variables
Attribute variableName.VB_VarUserMemId = 0 ' Zero indicates that this is the default member of the class.
Attribute variableName.VB_VarDescription = "some string" ' Adds the text to the Object Browser information for this variable.

'Procedures 
Attribute procName.VB_Description = "some string" ' Adds the text to the Object Browser information for the procedure.
Attribute procName.VB_UserMemId = someInteger
    '  0: Makes the function the default member of the class.
    ' -4: Specifies that the function returns an Enumerator.

有关它们的更多信息,请访问https://christopherjmcclellan.wordpress.com/2015/04/21/vb-attributes-what-are-they-and-why-should-we-use-them/

我当时在想,有没有办法在代码中获取/读取这些属性?例如

Sub BarMacroName()
'
' BarMacroName Macro
' Bar Macro Description
'
    Dim var

    MsgBox VB_Description 'display this module's description
    MsgBox VB_Name 'display this module's description

End Sub

不仅是描述和名称,而且总的来说,我们实际上可以读取代码本身内部的属性吗?

编辑:我正在专门查看是否可以在VBA脚本本身中提取Attribute值。我正在研究恶意软件漏洞,并且很好奇是否有人可以在VBA模块的描述中嵌入恶意代码。

0 个答案:

没有答案