0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excelで非表示の名前を表示して削除するマクロ

Posted at

Excelで非表示の名前を表示して削除するマクロ

マクロをアドインとして登録する手順

Excelを便利に!アドインの作成

マクロ

非表示となっている名前を表示状態にし、Print_AreaとPrint_Titles以外のすべての名前の定義を削除する

Sub 名前削除()
    Dim nm As Name
    Dim i As Long

    ' コレクションから項目を削除するため、逆順ループを使用
    For i = ActiveWorkbook.Names.Count To 1 Step -1
        Set nm = ActiveWorkbook.Names(i)
        
        ' 非表示の名前を表示状態にする
        If nm.Visible = False Then
            nm.Visible = True
            Debug.Print "非表示だった名前を表示: " & nm.Name
        End If
        
        ' 名前が「Print_Area」または「Print_Titles」を含む場合は残し、それ以外は削除
        If InStr(1, UCase(nm.Name), "PRINT_AREA", vbTextCompare) = 0 And _
           InStr(1, UCase(nm.Name), "PRINT_TITLES", vbTextCompare) = 0 Then
            nm.Delete
        End If
    Next i
    
    MsgBox "Print_AreaとPrint_Titles以外の名前を削除しました。"
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?