vba 如何从电子表格上的按钮调用用户表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11085454/
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
How to call userform from button on spreadsheet?
提问by mezamorphic
I have my initialiser function within the userform "module" but when I go to assign a function to be called from my button, excel doesnt show the userform "module" functions being available.
我在用户表单“模块”中有我的初始化函数,但是当我去分配一个要从我的按钮调用的函数时,excel 没有显示用户表单“模块”函数可用。
How can I get my userform to display upon the press of a button from the spreadsheet?
如何在按下电子表格中的按钮时显示我的用户表单?
回答by datatoo
double-click the button you have created and place the call to your macro in the code that displays
双击您创建的按钮并在显示的代码中调用您的宏
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub
回答by xchiltonx
You need to cut/paste your code in to a worksheet macro: 1. select and cut your macro 2. double click on sheet1 (Microsoft Excel Objects) 3. paste 4. save Now you can run your macro
您需要将代码剪切/粘贴到工作表宏中: 1. 选择并剪切您的宏 2. 双击 sheet1(Microsoft Excel 对象) 3. 粘贴 4. 保存 现在您可以运行您的宏
EDIT: Module if I remember correctly are reserved for OnAction
编辑:如果我没记错的话,模块是为 OnAction 保留的
回答by user10818876
If you want to easily call-up your form on the worksheet without going to VBE, you can simply create a macro (not with PrivateSub
) with:
如果您想在不使用 VBE 的情况下轻松调用工作表上的表单,您可以简单地创建一个宏(而不是使用PrivateSub
):
Sub CommandButton_Click ()
UserForm1.Show
End Sub