vba 如何动态获取当前多页标签值的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19573496/
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 dynamically get the value of current multipage tab value?
提问by CBC_NS
Community, I am currently hiding my tabs on my userform multipage except for the current tab. The user can click buttons to switch back and forth between pages. Some buttons share sub routines. When a user clicks a button, it hides the previous tab once the new tab has been selected. I suppose this is a dual question.
社区,我目前正在用户表单多页上隐藏我的选项卡,但当前选项卡除外。用户可以单击按钮在页面之间来回切换。一些按钮共享子程序。当用户单击一个按钮时,一旦选择了新选项卡,它就会隐藏上一个选项卡。我想这是一个双重问题。
1) How can I get the previous tab selection value?
1) 如何获取上一个选项卡选择值?
2) How can I loop through my tab values? My objective is to test the current tab caption or value against all the others. Figured this would be an easy way of hiding them all regardless as to which page and which button calls the subroutine.
2) 如何循环我的选项卡值?我的目标是针对所有其他选项卡测试当前选项卡标题或值。认为这将是一种将它们全部隐藏的简单方法,无论哪个页面和哪个按钮调用子例程。
Right now I only have this for one tab button...
现在我只有一个标签按钮...
Sub NewCreditSetup()
MultiPage1.Pages(1).Visible = True
MultiPage1.Value = 1
MultiPage1.Pages(0).Visible = False
//More code displaying tab...irrelevant
End Sub
采纳答案by CuberChase
You can use the tab change event to determine when the tab is changed and store the current tab index
as a variable. Then when the tab is changed again, the tab in this variable becomes the previous tab.
您可以使用选项卡更改事件来确定选项卡何时更改并将当前选项卡存储index
为变量。然后再次更改选项卡时,此变量中的选项卡将成为上一个选项卡。
Ie:
IE:
Private iPrevTab As Integer
Private iCurTab As Integer
Private Sub MultiPage1_Change()
iPrevTab = iCurTab
iCurTab = MultiPage1.Index
'You can also check here what that tab is to do something with it
If MultiPage1.Value = MultiPage1.Pages("mySpecialPage").Index Then
'Go Nuts
End If
End Sub
You can then loop through all the tabs and check against their name, caption or index. Eg:
然后,您可以遍历所有选项卡并检查它们的名称、标题或索引。例如:
Private Sub LoopTabs()
Dim ii as Integer
for ii = 1 to MultiPage1.Pages.Count
If MultiPage1.Pages(ii).Index = iPrevTab Then
Debug.Print MultiPage1.Pages(ii).Name & " " & MultiPage1.Pages(ii).Caption
End If
Next ii
End Sub
It's probably also worth noting to be careful showing and hiding tabs as it is not common and could possibly confuse the user. I'll leave that up to you though.
可能还值得注意的是要小心地显示和隐藏选项卡,因为它并不常见并且可能会使用户感到困惑。不过,我会把它留给你。
回答by Rtronic
I think that will help you.
我认为这会对你有所帮助。
Dim m As String
m = MultiPage1.SelectedItem.Caption
MsgBox m