vba 我可以从工作表中的按钮启动用户表单吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27583725/
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
Can i launch userform from a button in a Sheet
提问by Vijay Kumar
I was very curious with the answer in the above link.
我对上面链接中的答案很好奇。
My question is, Can I pop up a graph with click of button(The button is on Sheet1) and when i go bach to
Sheet thr graph is gone
我的问题是,我可以通过单击按钮弹出一个图表(按钮在 Sheet1 上),当我转到
Sheet thr 时,图表消失了
回答by Alexander Bell
Pertinent to your question as it is worded in the Title (i.e. 'Can i launch userform from a button in a Sheet'), you can implement this functionality in two simple steps:
与标题中措辞的问题相关(即“我可以从工作表中的按钮启动用户表单吗”),您可以通过两个简单的步骤来实现此功能:
1). From Excel 'Developer' tab select Insert
-> Button
. By default, it will create a new Button1
and corresponding Click event handle will be added to the Module1
1)。从 Excel 的“开发人员”选项卡中选择Insert
-> Button
。默认情况下,它会创建一个新的Button1
并且相应的 Click 事件句柄将被添加到 Module1
Sub Button1_Click()
End Sub
2). Provided that you have a User Form named UserForm1
, add a single statement in that event handle that will open the UserForm1 on Button click:
2)。假设您有一个名为 的用户窗体UserForm1
,请在该事件句柄中添加一条语句,该语句将在单击按钮时打开 UserForm1:
Sub Button1_Click()
UserForm1.Show
End Sub
In case you are trying to implement additional functionality, please include your code snippet highlighting the problematic part.
如果您尝试实现其他功能,请包含您的代码片段,突出显示有问题的部分。
Hope this will help. Best regards,
希望这会有所帮助。此致,
回答by Matteo NNZ
Let's do it by point and basing on the answer you have posted.
让我们根据您发布的答案逐点进行。
Can I pop up a graph with click of button(The button is on Sheet1)?
我可以通过单击按钮弹出图形吗(按钮在 Sheet1 上)?
Yes, you can. You need to:
是的你可以。你需要:
- Put a Button on Sheet1 and associate to it a macro, let's say
popUpChart
; Create and show the chart:
Sub popUpChart() Dim ch As UserForm1 Set ch = New UserForm1 'ch.CommandButton1_Click() 'a) Uncomment the line above if you want to invoke the button press before to show the chart 'b) If you decide to uncomment, remember to change the sub from "Private" to "Public" ch.Show End Sub
- 在 Sheet1 上放置一个 Button 并将其关联到一个宏,比方说
popUpChart
; 创建并显示图表:
Sub popUpChart() Dim ch As UserForm1 Set ch = New UserForm1 'ch.CommandButton1_Click() 'a) Uncomment the line above if you want to invoke the button press before to show the chart 'b) If you decide to uncomment, remember to change the sub from "Private" to "Public" ch.Show End Sub
when i go bach to Sheet thr graph is gone
当我去 bach 到 Sheet thr 图表消失了
I don't understand well what you mean here. Do you mean "I want the graph to be gone when I go back to the sheet" or "I would like the chart to stay here but actually it's gone?
我不太明白你在这里的意思。您的意思是“当我回到工作表时,我希望图表消失”或“我希望图表保留在此处但实际上它已经消失了?
a) In the first case, it's enough to remove the image from the Image control of the form;
b) In the second case, it's enough to remove the Set
statement from the button's macro.
a) 第一种情况,把图片从窗体的Image控件中去掉就可以了;b) 在第二种情况下,Set
从按钮的宏中删除语句就足够了。