oMath - 在 Word 中评论方程式 VBA
oMath - Comment an Equation in Word VBA
你好我需要编程在某些情况下添加注释,在我的静态测试中它完成了代码但最后也给出了类型不匹配错误。请问我该如何修改?
Sub EquTest()
Dim objRange As range
Dim objEq As OMath
Set objRange = Selection.range
objRange.Text = "Celsius = (5/9)(Fahrenheit - 32)"
Set objRange = Selection.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
Set objEq = objEq.range.Comments.Add(Selection.range, "Blah Blah")
'Comment added but then Type mismatch displayed
End Sub
.Comments.Add
returns 评论,而不是 objEq
期望的 OMath 对象。此外,您不需要多次使用 Selection
Sub EquTest()
Dim objRange As Range
Dim objEq As OMath
Set objRange = Selection.Range
objRange.Text = "Celsius = (5/9)(Fahrenheit - 32)"
Set objRange = objRange.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
'method 1 - if all you need to do is add the comment
objEq.Range.Comments.Add objRange, "Blah Blah"
'method 2 - if you need to do more with the comment once it has been added
With objEq.Range.Comments.Add(objRange, "Blah Blah")
End With
'method 3 - alternative to method 2
Dim cmt As Comment
Set cmt = objEq.Range.Comments.Add(objRange, "Blah Blah")
End Sub
你好我需要编程在某些情况下添加注释,在我的静态测试中它完成了代码但最后也给出了类型不匹配错误。请问我该如何修改?
Sub EquTest()
Dim objRange As range
Dim objEq As OMath
Set objRange = Selection.range
objRange.Text = "Celsius = (5/9)(Fahrenheit - 32)"
Set objRange = Selection.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
Set objEq = objEq.range.Comments.Add(Selection.range, "Blah Blah")
'Comment added but then Type mismatch displayed
End Sub
.Comments.Add
returns 评论,而不是 objEq
期望的 OMath 对象。此外,您不需要多次使用 Selection
Sub EquTest()
Dim objRange As Range
Dim objEq As OMath
Set objRange = Selection.Range
objRange.Text = "Celsius = (5/9)(Fahrenheit - 32)"
Set objRange = objRange.OMaths.Add(objRange)
Set objEq = objRange.OMaths(1)
objEq.BuildUp
'method 1 - if all you need to do is add the comment
objEq.Range.Comments.Add objRange, "Blah Blah"
'method 2 - if you need to do more with the comment once it has been added
With objEq.Range.Comments.Add(objRange, "Blah Blah")
End With
'method 3 - alternative to method 2
Dim cmt As Comment
Set cmt = objEq.Range.Comments.Add(objRange, "Blah Blah")
End Sub