问题是这样的,我在VBA中测试一个对象的一个属性,这个属性是可写的布尔型。例如设对象名为oObjToTest,要测的属性名是sPropName。我先通过CallByName oObjToTest, sPropName, VbLet, bValue这个语句改变sPropName的值。其中bValue是布尔类型,其值为Non-COM compliant True,就是赋给它一个非零值,而不是赋给它一个True。运行上面的语句后oObjToTest.sPropName=False。然后我又用这个赋值语句:oObjToTest.sPropName=bValue,运行后oObjToTest.sPropName=True。就是说两次赋值结果竟然是不同的!有哪位大虾知道原因吗?不排除这个对象本身有bug的可能性。
按道理这两种处理应该一样,是不是用CallByName时,你的代码前面有些处理将这个bValue变为0
oObjToTest.sPropName=bValue'result: sPropName=True
Private Sub CommandButton1_Click()
Sheet1.Range("a1").Characters.Insert "xxx"
Sheet1.Range("a1").Characters.Font.Color = vbRed
End SubPrivate Sub CommandButton2_Click()Dim f As Font
Set f = Sheet1.Range("a1").Characters.Font
bvalue = True
CallByName f, "Bold", VbLet, bvalue
MsgBox "Sheet1.Range(""a1"").Characters.Font.Bold=" & Sheet1.Range("a1").Characters.Font.Bold
bvalue = False
CallByName f, "Bold", VbLet, bvalue
MsgBox "Sheet1.Range(""a1"").Characters.Font.Bold=" & Sheet1.Range("a1").Characters.Font.Bold
End SubPrivate Sub CommandButton3_Click()bvalue = True
Sheet1.Range("a1").Characters.Font.Bold = bvalue
MsgBox "Sheet1.Range(""a1"").Characters.Font.Bold=" & Sheet1.Range("a1").Characters.Font.Bold
bvalue = False
Sheet1.Range("a1").Characters.Font.Bold = bvalue
MsgBox "Sheet1.Range(""a1"").Characters.Font.Bold=" & Sheet1.Range("a1").Characters.Font.Bold
End Sub