vba Office 2010 UserForm 处理多页控件中的页面

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

Office 2010 UserForm handling Pages in MultiPage Control

vbams-office

提问by DKSan

I am currently working on migrating from Office 2002 SP3 to Office 2010.

我目前正在从 Office 2002 SP3 迁移到 Office 2010。

In an Excel Workbook with heavy use of VBA i am running into the following Problem:

在大量使用 VBA 的 Excel 工作簿中,我遇到了以下问题:

The following function is working like a charme in 2002, but crashes when opened with 2010.

以下函数在 2002 年运行得非常好,但在 2010 年打开时崩溃。

Private Function fktSeeall()
   Dim pPage As Page, cCont As Control, mpMultiPage As Control

   If Seeall Then
       cbButton2.Caption = "Leere ausblenden"
   Else
       cbButton2.Caption = "Alle anzeigen"
   End If
   For Each mpMultiPage In Me.Controls
       If TypeName(mpMultiPage) = "MultiPage" Then
           For Each pPage In mpMultiPage.Pages
               pPage.Visible = Seeall
               For Each cCont In pPage.Controls
                   If TypeName(cCont) = "TextBox" And cCont.Text <> "" Then
                       pPage.Visible = True
                       mpMultiPage.Value = Right(pPage.Name, 1) - 1
                   End If
               Next cCont
           Next pPage
       End If
   Next
End Function

The boolean Seeallis set outside the function. All pages are containing one textbox. If seeall is set to false, every Page exept the ones with filled Textboxes are hidden. If set to true, all Pages are shown again.

布尔值Seeall在函数外设置。所有页面都包含一个文本框。如果 seeall 设置为 false,则除了填充了文本框的页面之外的每个页面都将被隐藏。如果设置为 true,则会再次显示所有页面。

Office 2010 fails at the line For Each pPage In mpMultiPage.Pageswith error message code 13 "Type Dismatch"

Office 2010 在For Each pPage In mpMultiPage.Pages错误消息代码 13“类型不匹配”的行失败

It also fails if i use

如果我使用它也会失败

For Each pPage In MultiPage1.Pages
    pPage.Visible = Seeall
    For Each cCont In pPage.Controls
        If TypeName(cCont) = "TextBox" And cCont.Text <> "" Then
            pPage.Visible = True
            MultiPage1.Value = Right(pPage.Name, 1) - 1
        End If
    Next cCont
Next pPage

I dont get the point, why the new office version fails at this stage of my code.

我不明白为什么新的办公版本在我的代码的这个阶段失败。

This is a screenshot of the UserForm: enter image description here

这是用户窗体的屏幕截图: 在此处输入图片说明

回答by osknows

Ok figured it out!

好吧想通了!

From Excel 2007 onwards the Object Model has an object called Page which isn't the same as the Forms Page.

从 Excel 2007 开始,对象模型有一个称为页面的对象,它与表单页面不同。

Reference the Form Page property explicitly using Dim pPage As msforms.Pageinstead of Dim pPage As Page

使用Dim pPage As msforms.Page而不是显式引用表单页面属性Dim pPage As Page