Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel vba, deleting all names from a workbook without a loop

Tags:

excel

vba

I'm trying to delete all names from an excel workbook using VBA without using a loop.

I'm currently using the code below, but this is very slow as there are several thousand names in the workbook.

Any suggestions would be appreciated!

Sub deleteAllNames()
Dim xName As Name

For Each xName In Application.ActiveWorkbook.Names
       xName.Delete
Next
End Sub
like image 507
Charteris Avatar asked Sep 16 '25 09:09

Charteris


1 Answers

Not possible without some complicated hacky way or messing with the XML, but this should be faster:

Dim i As Long
Application.Calculation = xlCalculationManual
For i = ThisWorkbook.Names.Count To 1 Step -1
    ThisWorkbook.Names(i).Delete
Next
Application.Calculation = xlCalculationAutomatic
like image 106
Slai Avatar answered Sep 17 '25 23:09

Slai