gpt4 book ai didi

excel - 如何在初始化期间隐藏某些用户表单字段?

转载 作者:行者123 更新时间:2023-12-04 22:28:43 28 4
gpt4 key购买 nike

所以我有一个由 Multipages 组成的用户表单其中一页包含 togglebuttons隐藏和取消隐藏用户窗体以及 excel 工作表上的字段。下图显示了切换按钮页面。

enter image description here

HAZOP/SIL & LOPA 的代码是相同的,只是它隐藏的字段不同。下面是 HAZOP 切换按钮的代码。

Private Sub togbHAZOP_Click()

If togbHAZOP = True Then

Sheets("Updated Hours EST").Rows("6:27").EntireRow.Hidden = False
Sheets("SCOPE").Rows("31:37").EntireRow.Hidden = False
Sheets("SUMMARY").Rows("5:8").EntireRow.Hidden = False
Frame5.Enabled = True
Frame5.Visible = True
Frame6.Enabled = True
Frame6.Visible = True
Frame7.Enabled = True
Frame7.Visible = True
HazOp.Enabled = True
HazOp.Visible = True

Else
Sheets("Updated Hours EST").Rows("6:27").EntireRow.Hidden = True
Sheets("SCOPE").Rows("31:37").EntireRow.Hidden = True
Sheets("SUMMARY").Rows("5:8").EntireRow.Hidden = True
Frame5.Enabled = False
Frame5.Visible = False
Frame6.Enabled = False
Frame6.Visible = False
Frame7.Enabled = False
Frame7.Visible = False
HazOp.Enabled = False
HazOp.Visible = False

End If

End Sub

目前的初始化代码,但它不起作用,给出一个错误,说 "Run-time error 438: Object doesn't support this property or method"
Private Sub UserForm_Initialize()

WizardProp.MultiPage1.Value = 0
Me.MultiPage1.Style = fmTabStyleNone
togbHAZOP.Frame5.Enabled = False
togbHAZOP.Frame5.Visible = False
togbHAZOP.Frame6.Enabled = False
togbHAZOP.Frame6.Visible = False
togbHAZOP.Frame7.Enabled = False
togbHAZOP.Frame7.Visible = False
togbHAZOP.HazOp.Enabled = False
togbHAZOP.HazOp.Visible = False

End Sub

我遇到的问题是 如何隐藏代码开头的用户表单中的某些字段并基于用户使用 togglebuttons 的选择将隐藏/取消隐藏,因为此时我必须单击切换按钮然后取消单击以获取隐藏链接字段的位置,并且每次在初始化期间都这样做可能会很麻烦。

最佳答案

请注意,您可以减少如下代码。替换 TruetogbHAZOP.ValueFalseNot togbHAZOP.ValueIf togbHAZOP = True部分。所以你不需要重复整个代码。

Private Sub togbHAZOP_Click()
Sheets("Updated Hours EST").Rows("6:27").EntireRow.Hidden = Not togbHAZOP.Value
Sheets("SCOPE").Rows("31:37").EntireRow.Hidden = Not togbHAZOP.Value
Sheets("SUMMARY").Rows("5:8").EntireRow.Hidden = Not togbHAZOP.Value
Frame5.Enabled = togbHAZOP.Value
Frame5.Visible = togbHAZOP.Value
Frame6.Enabled = togbHAZOP.Value
Frame6.Visible = togbHAZOP.Value
Frame7.Enabled = togbHAZOP.Value
Frame7.Visible = togbHAZOP.Value
HazOp.Enabled = togbHAZOP.Value
HazOp.Visible = togbHAZOP.Value
End Sub

由于 togbHAZOP是一个切换它没有框架 togbHAZOP.Frame5这可能就是这里的问题。它可能应该是这样的:
Private Sub UserForm_Initialize()
WizardProp.MultiPage1.Value = 0
Me.MultiPage1.Style = fmTabStyleNone
Me.Frame5.Enabled = False
Me.Frame5.Visible = False
Me.Frame6.Enabled = False
Me.Frame6.Visible = False
Me.Frame7.Enabled = False
Me.Frame7.Visible = False
Me.HazOp.Enabled = False
Me.HazOp.Visible = False
End Sub

关于excel - 如何在初始化期间隐藏某些用户表单字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55264745/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com