Excel 常量“True”的计算结果为 True,常量“vbTrue”的计算结果为 -1。我一直将它们视为 VBA 代码中可互换的,但事实并非如此。这两个常量产生不同结果的地方之一是设置复选框。将 CheckBox.value 设置为 True 会产生预期结果,但将其设置为 vbTrue 会使 CheckBox 处于 TripleState。
Sub setCkBox1()
CheckBox1.TripleState = False
CheckBox1.Value = vbTrue '<<<< the check mark is dimmed to show TripleState is True
Debug.Print CheckBox1.TripleState: Stop '<<<< even though it won't admit it
CheckBox1.Value = True '<<<< check mark is not dimmed
End Sub
所以我的问题是,VBA 中还有哪些地方这两个常量不可互换?
最佳答案
True
是 bool 值,vbTrue
是长整型。在 bool 值和长整型不可互换的地方,它们不可互换。
关于excel - vbTrue 不是 True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15124840/