Word - 文档目标代码参考
我有一个 Word 文档,我在其中从 Control Toolkit 创建了一个复选框。我已在 Word 文档中添加了一个文本框,仅当单击该复选框时该文本框才可见。我有需要根据另一段类似代码中的复选标记使文本框可见的代码。
我需要的是我放在文档上的文本框的名称,以便我可以在代码中引用它...另一个文本框是 27,我是否只需要尝试增加数字,直到我幸运或在那里有什么疯狂的方法可以让我看看数字是多少?
Private Sub OtherChk_Click()
If OtherChk = False Then
ActiveDocument.Shapes("Text Box ??").Select
Selection.ShapeRange.Visible = msoTrue
Else
ActiveDocument.Shapes("Text Box ??").Select
Selection.ShapeRange.Visible = msoFalse
End If
End Sub
I have a word document on which I have created a checkbox from the Control Toolkit. I have added a text box to the word document that I want visible only when the check box is clicked. I have the code I need to make the text box visible based on the checkmark from another similar piece of code.
What I need is the name of the text box that I put on the document so I can refer to it in my code...the other text box is 27, do I just need to try incrementing numbers until I get lucky or is there some method to the madness where I can look to see what the number is?
Private Sub OtherChk_Click()
If OtherChk = False Then
ActiveDocument.Shapes("Text Box ??").Select
Selection.ShapeRange.Visible = msoTrue
Else
ActiveDocument.Shapes("Text Box ??").Select
Selection.ShapeRange.Visible = msoFalse
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于在 Word 中您可以谈论内容控件、表单字段或旧式 ActiveX 控件,每个控件都有自己的怪癖,因此很难直接回答这样的问题。
例如,我创建了一个新的word文档(word 2010),单击开发人员选项卡并下拉功能区中的“控件工具栏”按钮,列出了“旧版表单”和“activex控件”,
我单击了“设计模式”按钮,然后选择文本框activex控件,放在窗体上,右键单击它并选择“属性”,
弹出非常老派的属性浏览器(我认为这些代码多年来没有在word中被触及),但是,在顶部,您有控件名称,默认为 TextBox1
您可以将该名称更改为您想要的任何名称,然后通过该名称引用该控件。
您可能需要通过检查 NAME 属性的所有控件执行 for-next (我不确定索引集合是否会在名称上建立索引或仅在索引号上建立索引)。
Since with word you can be talking about Content controls, Form fields or Older style activex controls, each of which have their own quirks, it's tough to answer a question like this directly.
For instance, I created a new word doc (word 2010), clicked the developer tab and dropped down the "control toolbar" button in the ribbon, there's "Legacy forms" and "activex controls" listed,
I clicked the DESIGN MODE button, then chose the Textbox activex control, dropped on on the form, right clicked it and selected "Properties"
that pops up the VERY old school looking properties browser (I don't think that code has been touched in word in years), but, at the top, you have the controlname, defaulted to TextBox1
You can change that name to whatever you want, and then reference the control via that name.
You MAY need to do a for-next through all the controls checking the NAME property (I'm not sure off hand if the indexed collection will index on name or just on the index number).