我在一个填充了工作表的用户表单中有一个组合框。如果选择工作表,则会激活工作表,以便您可以选择取消保护。
我的问题是,如果我选择带有组合框的工作表,它会跳转到该工作表。
我尝试在最后设置Application.Calculation = xlCalculationManual
和Application.ScreenUpdating = False
,然后使用If
- 语句进行尝试。它不起作用。
Public comBox2 As Boolean
Private Sub ComboBox2_Change()
Dim sName As String 'name of sheet to show
comBox2 = True
sheetName = ComboBox2.Value
With ActiveWorkbook.Sheets(sheetName)
.Activate
End With
End Sub
Sub Userform_initialize()
If comBox2 Then
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ElseIf comBox2 = False Then
comBox2 = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End If
End Sub
答案 0 :(得分:2)
Public comBox2 As Boolean
Private Sub ComboBox2_Change()
Dim sName As String 'name of sheet to show
comBox2 = True
sheetName = ComboBox2.Value
End Sub
Sub Userform_initialize()
If comBox2 Then
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ElseIf comBox2 = False Then
comBox2 = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End If
End Sub
所以我删除了表格的激活。现在我要做的是在一个带有标题“unprotect”的ti组合框旁边放一个按钮,然后把代码放在不受保护的地方,如:
Activeworkbook.sheets(ComboBox2.value).Unprotect "password" ' in case there is fixed password
或者如果有不同的密码那么
Dim pass As Variant
pass = InputBox("Password?")
Activeworkbook.sheets(ComboBox2.value).Unprotect pass
答案 1 :(得分:1)
如果组合框位于工作表中,请检查组合框的工作表是否为活动工作表:
Private Sub ComboBox2_Change()
If ComboBox2.Parent.Name = ActiveSheet.Name Then Exit Sub
ActiveWorkbook.Sheets(sheetName).Activate
End Sub
如果是以表格形式:
Private Sub ComboBox2_Change()
If ComboBox2.Text = ActiveSheet.Name Then Exit Sub
ActiveWorkbook.Sheets(sheetName).Activate
End Sub