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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:46:25  来源:igfitidea点击:

ActiveX textbox value

vbaword-vba

提问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 syntax
ActiveDocument.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

  1. To get the valueof a standard textbox, use this: ActiveDocument.Shapes(1).TextFrame.TextRange.Text

  2. To get the valueof ActiveX controls (OLEobjects), use this syntax where TextBox1is the control name, use ActiveDocument.TextBox1.Value

  3. To get the nameof ActiveX controls, use this: ActiveDocument.InlineShapes(1).OLEFormat.Object.Name

  1. 要获得价值一的标准的文本框,使用此: ActiveDocument.Shapes(1).TextFrame.TextRange.Text

  2. 要获取价值ActiveX控件(OLEobjects) ,使用此语法,其中TextBox1为控制名称,使用 ActiveDocument.TextBox1.Value

  3. 要获取名称ActiveX控件,使用此: ActiveDocument.InlineShapes(1).OLEFormat.Object.Name