VBA - 根据Combobox选择隐藏框架中的页面(选项卡)

时间:2017-10-02 23:21:37

标签: excel vba combobox multipage

我已经编写了VBA代码,根据组合框选择显示隐藏的选项卡。组合框中有七个选项,每个选项对应框架中的七个隐藏选项卡。

RewriteEngine On

# Rewrite to filesystem path (in the server config)
RewriteRule ^/specialrequest$ /var/www/html/script.php [L]

# Front controller
RewriteRule ^/index\.html$ - [L]
RewriteCond %{LA-U:REQUEST_FILENAME} !-f
RewriteCond %{LA-U:REQUEST_FILENAME} !-d
RewriteRule ^/. /index.html [L]

我似乎遇到的问题是,如何确保隐藏其他标签?由于人们只能在组合框中单击一个选项,但他们可能会错误地单击一个选项,然后单击正确的选项。根据组合框中的选定项目,只能看到一个选项卡。其他六个应该被隐藏。

我想在sub的末尾有一个For-Each-Next循环,它禁用任何与iPage变量不匹配的标签,但是我很难弄清楚如何在For中寻找框架和页面每个Next循环。变量声明会是什么?

2 个答案:

答案 0 :(得分:1)

未经测试,因此可能需要进行细微调整......

Private Sub CBO_EntryType_Change()

    Dim iPage, arrPages, x As Long
    arrPages = Array("Abstracts", "Awards", "Career Fairs", "Editorials", _
                      "Rankings", "Tradeshows", "Social Media")

    'find the index in the array...
    iPage = Application.Match(Me.CBO_EntryType.Value, arrPages, 0)

    'if got a match then loop over the pages and show/hide
    If Not IsError(iPage) Then
        For x = 0 To Me.MultiPage1.Pages.Count-1
            Me.MultiPage1.Pages(x).Visible = ((x+1) = iPage)
        Next x
    End If

End Sub
编辑 - @jstola,我认为相似......

答案 1 :(得分:1)

以下代码假设多页中的页面标题反映了CBO_EntryType中的列表:

Private Sub CBO_EntryType_Change()
    Dim iPage As Long
    For iPage = 0 To Me.MultiPage1.Pages.Count - 1
        With Me.MultiPage1.Pages(iPage)
            .Visible = (.Caption = CBO_EntryType.Value)
        End With
    Next
End Sub