Run Time error 1004 Method 'Names' of object '_Global' failed

pbishop

New Member
Joined
Jan 11, 2021
Messages
5
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
Platform
  1. Windows
We have this code below. For one user, it seems, she gets the 1004 Method 'Names' of object '_Global' failed the first time she opens this XLSM file. If she closes the XLSM file and comes back in she doesn't get it the second time. If we add Names to a watch it just gives use that same error. I'll attach a screen shot of that. Again though it seems to work for her the second time through and nobody else seems to have the error. Any idea what could be causing this? Also she was on 32bit Excel and got the error and has now been upgraded to 64bit and still gets it.

Dim nName As Name



For Each nName In Names

If InStr(1, nName.RefersTo, "#REF!") > 0 Then

nName.Delete

End If

Next nName



End Sub
 

Attachments

  • error 2 zoomed in.JPG
    error 2 zoomed in.JPG
    66.7 KB · Views: 32
I guess I'm still a little confused. We took over this XLS from someone who wrote it 15 plus years ago and converted it to XLSM and fixed it to work in 64bit Excel. Everything else is working and this only seems to be an issue for one user and she is using the same XLSM that others, who aren't having the issue, are using. I'm not even 100 percent for sure what this sub is doing. If you put Sheet1 or whatever it will only do that sheet correct? With sheet1 is it only doing one sheet regardless? I guess I'm asking with what I sent originally is that looping through one sheet(whatever it's called) or many sheets? I've never coded anything like that in VBA before. Again though it seems to only happen for one user and if she closes and reopens(without saving) it doesn't seem to happen the second time.
Do you know if she’s in the right sheet when the macro starts?

Is this the whole sub or there anything more?
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
@pbishop, your issue is caused due to VBA's implicitness. When a parent object is not explicitly indicated in the code, VBA tries to fill in this omission (in the background).
Under certain but very rare circumstances, VBA makes the wrong choice or fails at all.
The Names collection object is a member of the Workbook object. In this case, VBA would/should have chosen the ActiveWorkbook object (being a member of the Excel.Application object), which apparently failed.

If the code has to run against the same workbook the code is residing, then it's most likely the code below resolves your issue.
Rich (BB code):
Sub DeleteDeadNames()

    Dim nName As Excel.Name
    For Each nName In ThisWorkbook.Names
        If InStr(1, nName.RefersTo, "#REF!") > 0 Then
            nName.Delete
        End If
    Next nName
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top