' [043.xls] ' [Module1] のコード '★★☆ ブック内の全てのシートを選択する ☆★★ Option Explicit Sub start() UserForm1.Show End Sub ' [UserForm1] のコード Option Explicit Dim ws As Worksheet Private Sub CommandButton1_Click() Dim i As Integer 'シート(Title)の後へ3枚のシートを挿入 For i = 1 To 3 Worksheets.Add.Move after:=Sheets("Title") Next i CommandButton3.Enabled = True End Sub Private Sub CommandButton2_Click() With CommandButton2 If .Caption = "シート全選択" Then .Caption = "全選択解除" '全てのシートを選択します ThisWorkbook.Worksheets.Select Else .Caption = "シート全選択" Worksheets("Title").Select End If End With End Sub Private Sub CommandButton3_Click() 'シート削除時の警告やメッセージを表示させない Application.DisplayAlerts = False '指定したシート以外を削除 For Each ws In Worksheets If ws.Name <> "Title" Then ws.Delete End If Next CommandButton3.Enabled = False Application.DisplayAlerts = True End Sub Private Sub UserForm_Initialize() CommandButton1.Caption = "シート作成" CommandButton2.Caption = "シート全選択" CommandButton3.Caption = "新シートのみ削除" Me.Caption = "シートの操作" '指定シート以外があれば削除ボタンを使用可能にする For Each ws In Worksheets If ws.Name <> "Title" Then CommandButton3.Enabled = True Exit Sub End If Next CommandButton3.Enabled = False End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Worksheets("Title").Select End Sub