编辑:我使用整个代码修改了userform2特定代码
我有2个userforms和userform2代码定义如下。我的问题是从userform2组合框中选择的工作表(从工作表名称填充)要删除,如果代码最终显示userform1,则保持激活状态。但是如果我删除行" UserForm1.Show",makro运行良好并且删除成功。如何删除所选表单并在成功执行后显示userform1?在此先感谢您的帮助。
Userform2代码
Private Sub ToggleButton1_Click()
Dim i As Integer
i = ActiveWorkbook.Worksheets.Count
Application.DisplayAlerts = False
If UserForm2.ComboBox1.Value = "SILINECEK CARIYI SEÇIN" Then
MsgBox "CARI SEÇMEDINIZ"
Unload UserForm2
Application.Visible = True
Exit Sub
End If
If ToggleButton1.Value = True And i < 5 Then
ActiveWorkbook.Unprotect
Sheets("MASTER CARI").Visible = True
Worksheets(UserForm2.ComboBox1.Text).Delete
Unload UserForm2
Application.Visible = False
UserForm1.Show
ActiveWorkbook.Protect
Exit Sub
Else
ActiveWorkbook.Unprotect
Worksheets(UserForm2.ComboBox1.Value).Delete
Unload UserForm2
Application.Visible = True
End If
ActiveWorkbook.Protect
Application.DisplayAlerts = True
End Sub