作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 VBA(Excel 365(16.0.12527.20880),德语)我试图将复选框( Checkbox1
)的删除线属性设置为 False
按照Office VBA reference这应该有效。
以下代码放在Module1
中(简化)并更改 UserForm1.Checkbox1
的删除线值( UserForm1
和 Checkbox1
是静态的,通过 VBA 编辑器创建,而不是在运行时通过代码创建)。
Sub ChangeCheckBox()
UserForm1.CheckBox1.Caption = "Test" 'this triggers the Init-Procedure, which only sets the Height and Width of the UserForm. This shouldn't effect the problem, but I'm mentioning it here so it's clear that the form has been initialized. But if I leave it out, it's the same problem.
'Pre-Test - works fine
'Check initial value
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns false (as it should)
'Write value and check it
UserForm1.CheckBox1.Font.Strikethrough = False
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns false (as it should)
'Write value and check it again
UserForm1.CheckBox1.Font.Strikethrough = False
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns false (as it should)
'This next line seeems to cause the post-test failure
tmpString = ThisWorkbook.Worksheets("Sheet1").Cells(tmpIndex, tmpColumn).Value
Debug.Print tmpString 'returns the correct value
'Post-Test - fails!!!
'Check initial value
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns false (as it should)
'Write value and check it
UserForm1.CheckBox1.Font.Strikethrough = False
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns true (should still be false)
'Write value and check it again
UserForm1.CheckBox1.Font.Strikethrough = False
Debug.Print UserForm1.CheckBox1.Font.Strikethrough 'returns true (definitely should return false now)
End Sub
就我而言,出于某种原因,该命令将框设置为
True
而不是
False
.到目前为止,我已将问题定位到特定的代码行。 “预测试”成功,“后测试”失败(其他一切正常)。请注意,我正在逐步使用 Debug模式,没有其他代码在“中间”执行。
tmpString = ThisWorkbook.Worksheets("Sheetname").Cells(tmpIndex, tmpColumn).Value
导致“后测试”失败?
最佳答案
我无法重现这个问题,我已经在 3 台不同的机器上尝试过。
但是,我记得大约 7 年前看到过类似的问题,我设法通过首先检查是否需要更改字体属性的值来解决它。
尝试替换所有出现的这个:
UserForm1.CheckBox1.Font.Strikethrough = False
有了这个:
If UserForm1.CheckBox1.Font.Strikethrough Then UserForm1.CheckBox1.Font.Strikethrough = False
这基本上设置了
.Font.Strikethrough
属性(property)到
False
仅当它已经是
True
因为否则就是
False
(显然)并且如果该属性的 setter 中有任何错误,那么这将跳过该错误。
Userform1.Checkbox...
所做的那样。 .我建议你阅读
this article由@MathieuGuindon 于 2017 年撰写。
关于vba - 从特定模块更改复选框的字体属性 "Strikethrough"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68916663/
我是一名优秀的程序员,十分优秀!