测试文本框值失败
所以这里(VBA Word):我选择一个特定的文本框并测试它的内容是否等于特定的字符串。所有这些都有效 - 但我总是得到错误的回应。当我发布 Debug.print 中的值时,显示“重要的事情”,这应该是真实的响应。触发文本的变化。从来没有。
(VBA Word 宏如下:)
Sub testit()
Dim WD as document
Dim StringOne as string
set WD = Application.ActiveDocument
StringOne = "Something Important"
'this line will always come back false - why?*
If WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = stringOne Then
WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = "Something More"
Else
' This will say "Something Important"
Debug.Print WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text
' And Just in case I typed something wrong let's enter it again into the textbox
WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = "Something Important"
End If
End Sub
这是一个更复杂程序的简化。我将测试几个文本框,出于演示原因,我将在 WORD 文档中按名称调用这些文本框并进行相应更改。 IE:更改.fontsize、.bold。等等。相应地。根据 WORD 文档的布局,某些文本框会有不同的设置。无论如何,如果我无法测试文本框中文本的值......它永远不会改变。
So here goes (VBA Word): I'm picking a specific Text Box and testing to see if it's contents are equal to a specific string. All of this works - except I always get a false response. When I post the value in Debug.print is shows "Something Important" which should have been a true response. triggering a change in the text. Never does.
(VBA Word macro follows:)
Sub testit()
Dim WD as document
Dim StringOne as string
set WD = Application.ActiveDocument
StringOne = "Something Important"
'this line will always come back false - why?*
If WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = stringOne Then
WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = "Something More"
Else
' This will say "Something Important"
Debug.Print WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text
' And Just in case I typed something wrong let's enter it again into the textbox
WD.Shapes.Range("Text Box 2").TextFrame.TextRange.Text = "Something Important"
End If
End Sub
This is a simplification of a more complex program. I will be tests several Text Boxes, Which I will call by name and change accordingly in the WORD document for presentation reasons. IE: Change the .fontsize, .bold. etc. Accordingly. Some textboxes will have different settings according to the layout of the WORD doc. Regardless, if I can't test the value of the text in a textbox... it will never change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令人惊讶的是,这是一个字符映射问题。
需要作为长度问题进行纠正
在字符串末尾似乎有一些图形需要的空白或格式字符,您可以将其剪掉。
Surprisingly, it is a character mapping problem.
needs to be corrected as a length issue
There seems to be a few blank or formatting characters that the graphic needs at the end of the string which you can trim off.