vba ActiveX 文本框值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8638022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActiveX textbox value
提问by jroeleveld
How do I get the value of a textbox in Word?
I know in excelthis is the right syntax: ActiveSheet.Shapes(x).Name
.
如何在 Word 中获取文本框的值?我知道在excel 中这是正确的语法:ActiveSheet.Shapes(x).Name
.
I thought in wordthis would be the right syntaxActiveDocument.Shapes(x).Name
,
but this doesn't seems to work.
我认为在这个词,这将是正确的语法ActiveDocument.Shapes(x).Name
,
但是这似乎并不工作。
With this piece of code I also couldn't find a textbox:
使用这段代码我也找不到文本框:
For i = 1 To ActiveDocument.Shapes.Count
MsgBox ActiveDocument.Shapes(i).Name
Next i
采纳答案by jroeleveld
I used tags (object properties -> assign a tag name) to edit the object's value. Use this syntax to change the value of a content control:
ActiveDocument.SelectContentControlsByTag("Your-Content-Control-Tag").Item(1).Range.Text = "your-preferred-value"
Anyway, thanks Rachel Hettinger for your patience ;).
我使用标签(对象属性 -> 分配标签名称)来编辑对象的值。使用此语法更改内容控件的值:
ActiveDocument.SelectContentControlsByTag("Your-Content-Control-Tag").Item(1).Range.Text = "your-preferred-value"
无论如何,感谢 Rachel Hettinger 的耐心;)。
回答by Rachel Hettinger
To get the valueof a standard textbox, use this:
ActiveDocument.Shapes(1).TextFrame.TextRange.Text
To get the valueof ActiveX controls (OLEobjects), use this syntax where
TextBox1
is the control name, useActiveDocument.TextBox1.Value
To get the nameof ActiveX controls, use this:
ActiveDocument.InlineShapes(1).OLEFormat.Object.Name
要获得价值一的标准的文本框,使用此:
ActiveDocument.Shapes(1).TextFrame.TextRange.Text
要获取价值的ActiveX控件(OLEobjects) ,使用此语法,其中
TextBox1
为控制名称,使用ActiveDocument.TextBox1.Value
要获取名称的ActiveX控件,使用此:
ActiveDocument.InlineShapes(1).OLEFormat.Object.Name