vba - 究竟什么是属性(property)程序?

标签 vba excel

据我了解,VBA 中有三种程序:

  1. 函数
  2. 程序
  3. 属性(property)手续

我在网上搜索过,但没有找到属性过程的明确定义。

最佳答案

属性过程的示例位于自定义类模块内。 可以检索(get)或输入其值(let)

在自定义类中 (clsExample)

Private pName As String
Public Property Get Name() As String
    Name = pName
End Property
Public Property Let Name(value As String)
    pName = value
End Property

您可以在标准子中使用一个,如下所示:

Sub example()

Dim exampleClass As clsExample
Set exampleClass = New clsExample
exampleClass.Name = "John Smith"
MsgBox (exampleClass.Name)

End Sub

一些优点是您可以为有意义的对象提供有意义的属性名称(即project.id,project.manager),另一个例子是您可以为对象提供只读的派生属性(仅使用get而不使用set) .

关于vba - 究竟什么是属性(property)程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41894863/

相关文章:

excel - 使用 Excel VBA 将单元格公式转换为文本

基于日期的 Python VLOOKUP - Pandas

php - PHP和Excel生成的制表符分隔文本文件的区别

python - 如何在Python上调用Excel中的值

excel - 搜索多个工作表并将其中列 A >0 的所有行复制到指定工作表

c#从excel文件中获取值列表

vba - 从 VBA 向 cmd 行发送 key 会丢失特殊 key

excel - 如何从 Outlook 宏发送 Excel 图表

vba - Excel VBA-时间延迟 : How to use Time Delay after running macro

VBA 在表格上设置缩放级别