My macro-enabled excel workbook is a large file that includes tabs I've brought into the workbook from third parties (eg, my client). I break links to any external data sources and I delete named ranges for any the tabs that I bring into the workbook. I have named ranges / cells that I use throughout the workbook, but I do not have any links to external files or data sources that I can tell from the queries and connections section of the data tab in the ribbon. The performance of my work has deteriorated significantly over time, and it was clear named ranges were an issue when a simple name "K" that I had given to "1,000" was creating a #DIV/0! error. The Name Manager will not open - I get the circle for a few seconds and nothing happens.
In my troubleshooting efforts, I now have a list of the named ranges / cells, most of which I did not create and have #REF! errors. I've also learned that there are "hidden names" that may be causing issues as well. On the Microsoft support page, I found a potential solution using the macro below pasted below. When I run the macro, I get a "Run-time error '7': out of memory" and I try to "debug" the macro, which is beyond my VBA skills. I had zipped the excel file previously in my troubleshooting efforts, and I noticed a 17.5MB file called "workbook.xml. There is a ton of the text in the XML file related to names and hidden names that is seemingly related to the names / hidden names, and all kind of #REF! errors. I've spent 5 months on this workbook and have plenty of previous versions of it, but going back to significantly earlier versions is almost the same as recreating it front scratch. ANY guidance would be much appreciated.
Remove Hidden Names
' Module to remove all hidden names on active workbook
Sub Remove_Hidden_Names()
' Dimension variables.
Dim xName As Variant
Dim Result As Variant
Dim Vis As Variant
' Loop once for each name in the workbook.
For Each xName In ActiveWorkbook.Names
'If a name is not visible (it is hidden)...
If xName.Visible = True Then
Vis = "Visible"
Else
Vis = "Hidden"
End If
' ...ask whether or not to delete the name.
Result = MsgBox(prompt:="Delete " & Vis & " Name " & _
Chr(10) & xName.Name & "?" & Chr(10) & _
"Which refers to: " & Chr(10) & xName.RefersTo, _
Buttons:=vbYesNo)
' If the result is true, then delete the name.
If Result = vbYes Then xName.Delete
' Loop to the next name.
Next xName
End Sub