vba 将用户表单多页启动到特定页面

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

Start userform multipage into a specific page

excelexcel-vbaexcel-2010vba

提问by forums

I have a Userform named SheetBox

我有一个名为SheetBox 的用户表单

SheetBoxcontains a 3-page multipage window

SheetBox包含一个 3 页的多页窗口

"page1" for selecting sheets to import
"page2" contains a pseudo progress bar
"page3" for selecting sheets to protect

用于选择要导入的工作表的“page1”
“page2”包含一个
用于选择要保护的工作表的伪进度条“page3”

What I need now is a method to open a specific page upon opening the Userform when a button on a worksheet is clicked

我现在需要的是一种在单击工作表上的按钮时打开用户窗体时打开特定页面的方法

ex:
ImportBttnopens page1 of userform
ProtctBttnopens page3 of userform

例如:
ImportBttn打开用户表单的page1
ProtctBttn打开用户表单的 page3

I'm doing this to reduce the number of userform I needed to create, instead of creating 3 separate userforms. This also helps reduce the filesize.

我这样做是为了减少我需要创建的用户表单的数量,而不是创建 3 个单独的用户表单。这也有助于减少文件大小。

回答by forums

This works too

这也有效

Sub ImportBttn_Click()
Load SheetBox: SheetBox.MultiPage1.Value = 0: SheetBox.Show
End Sub

Sub ProtctBttn_Click()
Load SheetBox: SheetBox.MultiPage1.Value = 2: SheetBox.Show
End Sub

this loads sheetbox first, changes the multipage page and shows it afterwards

这首先加载工作表框,更改多页页面并在之后显示它

but thanks for the caller method, will be useful when I need to know what button gets pressed

但是感谢调用者方法,当我需要知道按下了什么按钮时会很有用

回答by brettdj

In the UserForms InitialiseEvent, use Application.Callerto detect which button on the worksheet was pressed, and then set the multipage

在 UserFormsInitialise事件中,用于Application.Caller检测工作表上的哪个按钮被按下,然后设置multipage

Private Sub UserForm_Initialize()
Select Case Application.Caller
Case "ImportBttn"
`1st tab
Me.MultiPage1.Value = 0
Case "ProtctBttn"
`3rd tab
Me.MultiPage1.Value = 2
End Select
End Sub