0

有没有办法在 VBA 中确定对象的属性是否可以设置为不同的值?

比如检查属性是可写的还是不是只读的?

4

1 回答 1

0

检查属性的最简单方法是在 VBA 编辑器中使用光标突出显示它,然后按 Shift + F2。这将在对象浏览器中显示它的定义,它会在那里告诉你它是否是只读的。

以下屏幕截图是该workbook.worksheets.count属性的。

在此处输入图像描述

您可以通过暂停尝试设置属性的错误然后检查属性来在代码中检查只读。IE

iCountCheck = ThisWorkbook.Worksheets.Count
On Error Resume Next
ThisWorkbook.Worksheets.Count = 123   'Something that doesn't already equal iCountCheck
On Error Goto 0

If iCountCheck <> 123
   MsgBox "This is not read only"
Else
   MsgBox "This is read only"
End If 
于 2013-01-19T03:32:32.837 回答