'アクティブブックの参照設定を解除するマクロ(Excel97) 'MakeDialogSheet マクロを実行してダイアログシートを作成した後、 'RemoveReferences マクロを実行してください。 Option Explicit 'ダイアログシート名を適当に設定してください。 Const DialogSheetName = "dlgRemoveRef" Sub RemoveReferences() Dim oDialog As Object Dim oListBox As Object Dim oReferences As Object Dim oReference As Object Dim sName As String Dim i As Long Set oDialog = ThisWorkbook.DialogSheets(DialogSheetName) Set oListBox = oDialog.ListBoxes(1) Set oReferences = ActiveWorkbook.VBProject.References oDialog.DialogFrame.Caption = "参照設定の解除 - " & ActiveWorkbook.Name 'リストボックスの初期化 oListBox.RemoveAllItems For Each oReference In oReferences oListBox.AddItem oReference.Name & _ " / " & oReference.Description Next 'ダイアログボックスを表示 If Not oDialog.Show Then Exit Sub End If For i = oListBox.ListCount To 1 Step -1 If oListBox.Selected(i) Then On Error Resume Next oReferences.Remove oReferences(i) If Err <> 0 Then MsgBox "参照設定を解除することができませんでした。" _ & Chr(10) & oListBox.List(i), vbExclamation End If On Error GoTo 0 End If Next oListBox.RemoveAllItems End Sub 'ダイアログシートを作成するマクロ Sub MakeDialogSheet() Dim oDialog As DialogSheet Dim gw As Double For Each oDialog In ThisWorkbook.DialogSheets If oDialog.Name = DialogSheetName Then MsgBox (DialogSheetName & " はすでに存在します。") Exit Sub End If Next Set oDialog = DialogSheets.Add With oDialog gw = .Buttons(1).Height / 3 .Name = DialogSheetName With .DialogFrame .Caption = "" .Left = gw * 13 .Top = gw * 4 .Width = gw * 70 .Height = gw * 32 End With .Buttons(1).Left = gw * 72 .Buttons(2).Left = gw * 72 End With With oDialog.ListBoxes.Add(Left:=gw * 14, Top:=gw * 11, _ Width:=gw * 57, Height:=gw * 23) .MultiSelect = xlSimple .SendToBack End With With oDialog.Labels.Add(Left:=gw * 14, Top:=gw * 8, _ Width:=gw * 57, Height:=gw * 3) .Caption = "解除するライブラリを選択してください。" .SendToBack End With End Sub