Skip to content

Instantly share code, notes, and snippets.

@airstrike
Created October 14, 2020 06:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airstrike/a8019e7d9f99cebc944824ffdf100675 to your computer and use it in GitHub Desktop.
Save airstrike/a8019e7d9f99cebc944824ffdf100675 to your computer and use it in GitHub Desktop.
Excel VBA: Remove hidden names from workbook
Sub RemoveHiddenNames()
Dim tempname As Name
Application.ScreenUpdating = False
Dim Calc As Long
Calc = xlCalculationManual
If Application.Calculation <> xlCalculationManual Then Calc = xlCalculationSemiautomatic
Application.Calculation = xlCalculationManual
Dim statuspre As String
statuspre = "Deleting hidden names: ["
Dim namecount As Long, deleted As Long
namecount = ActiveWorkbook.Names.Count
On Error Resume Next
For Each tempname In ActiveWorkbook.Names
If tempname.Visible = False Then
tempname.Visible = True 'To help delete manually if the below fails
tempname.delete
deleted = deleted + 1
If deleted Mod 100 = 0 Then Application.StatusBar = statuspre & deleted & "/" & namecount & "]"
End If
Next
Application.StatusBar = statuspre & deleted & "/" & namecount & "]"
On Error GoTo 0
Application.ScreenUpdating = True
Application.Calculation = Calc
Exit Sub
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment