Option Explicit
Dim WithEvents CommandButton1 As CommandButton
Dim WithEvents CommandButton2 As CommandButton
Private Sub CommandButton1_Click()
'Delete button
Dim ctlListBox As ListBox
Set ctlListBox = Me.Controls("lstSheets")
Dim intItem As Integer
Application.DisplayAlerts = False
For intItem = 0 To ctlListBox.ListCount - 1
If ctlListBox.Selected(intItem) Then
ActiveWorkbook.Worksheets(ctlListBox.List(intItem)).Delete
End If
Next intItem
Set ctlListBox = Nothing
Unload Me
End Sub
Private Sub CommandButton2_Click()
'Cancel button
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim wksCurrent As Worksheet
Dim ctlNew As Control
'Resize the form
With Me
.Height = 195
.Width = 309
End With
'list box stufff
Set ctlNew = Controls.Add("Forms.ListBox.1", "lstSheets", True)
With ctlNew
.Height = 129.75
.Left = 8.25
.Top = 15
.Width = 290.25
.MultiSelect = fmMultiSelectMulti
End With
For Each wksCurrent In ActiveWorkbook.Worksheets
ctlNew.AddItem wksCurrent.Name
Next wksCurrent
'Delete button
Set CommandButton1 = Controls.Add("Forms.CommandButton.1", "CommandButton1", True)
With CommandButton1
.Height = 21
.Left = 105
.Top = 150
.Width = 48
.Caption = "Delete"
End With
'Cancel button
Set CommandButton2 = Controls.Add("Forms.CommandButton.1", "CommandButton1", True)
With CommandButton2
.Height = 21
.Left = 159
.Top = 150
.Width = 48
.Caption = "Cancel"
End With
End Sub