vba 隐藏 Word 文档上的命令按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2808810/
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 11:37:48  来源:igfitidea点击:

Hide command button on word doc

vbams-wordms-office

提问by DarkW1nter

I have a .doc with a command button (cmdStart) which opens a form. After populating the form I click a button to close the form and populate the .doc.

我有一个带有打开表单的命令按钮 (cmdStart) 的 .doc。填充表单后,我单击一个按钮关闭表单并填充 .doc。

I want to hide the initial cmdStart on the .doc as well when the form closes, Ive tries document.shapes(1).visible=false and cmdStart.visible=false but none seems to work.

我想在表单关闭时隐藏 .doc 上的初始 cmdStart,我尝试了 document.shapes(1).visible=false 和 cmdStart.visible=false 但似乎都没有工作。

Any ideas?

有任何想法吗?

thanks (ps I cant just opne the form from the autonew, I need the cmdStart visible to begin with)

谢谢(ps 我不能从 autonew 中打开表单,我需要 cmdStart 可见才能开始)

采纳答案by Dirk Vollmar

You have several options to deal with that. However, you won't be able to hide your command button but you will be able to remove it.

您有多种选择来处理这个问题。但是,您将无法隐藏命令按钮,但可以将其删除。

Removing a command button can be done by the following code:

删除命令按钮可以通过以下代码完成:

Private Sub CommandButton1_Click()
    CommandButton1.Select
    Selection.Delete
End Sub

(Note that usually you would be able to hide text in Word by setting the font hidden, e.g. by calling Selection.Font.Hidden. However, this does not affect controls.)

(请注意,通常您可以通过将字体设置为隐藏来隐藏 Word 中的文本,例如通过调用Selection.Font.Hidden。但是,这不会影响控件。)

If you deleted the button and you need it later on again you will have to re-create it. In that case it might be a good idea to mark the position of the button with a bookmark.

如果您删除了该按钮并且稍后再次需要它,则必须重新创建它。在这种情况下,用书签标记按钮的位置可能是个好主意。

Another option would be to use a MACRO button field. Such a field can be inserted from the Insert Fielddialog and can be used to launch a macro.

另一种选择是使用 MACRO 按钮字段。这样的字段可以从“插入字段”对话框中插入,并可用于启动宏。

回答by McGinn

If you really wanted to "hide" the button, you could set the Height and Width to 0.75 and it's virtually gone. Then resize back to "show". I've also seen people put them inside tags and hide the tag. Hope this helps

如果你真的想“隐藏”按钮,你可以将高度和宽度设置为 0.75,它实际上已经消失了。然后将大小调整回“显示”。我还看到人们将它们放在标签内并隐藏标签。希望这可以帮助