Deletion of Names from newly created Workbook that refers back to source .xlsm Workbook

AlInVegas2

New Member
Joined
Jun 19, 2019
Messages
20
I used an ActiveSheet.Copy followed by an ActiveWorkbook.SaveAs command to save an individual worksheet from the source workbook which has multiple worksheets. See below. Afterwards, I attempt to run code that deletes names from the newly created ActiveWorkbook. None of the subsequent For Each Loops work outside of the source worksheet. Appreciate any suggestions.

Dim DelName As Name

SaveFile = Range("$R$4").Value
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=SaveFile _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

For Each DelName In Application.ActiveWorkbook.Names
DelName.Delete
Next
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
When you're certain what your activeworkbook is, something like this might give you what you want:
VBA Code:
Dim xName As Name, i As Long
For i = ActiveWorkbook.Names.Count To 1 Step -1
    ActiveWorkbook.Names(i).Delete
Next i
 
Upvote 0
When you're certain what your activeworkbook is, something like this might give you what you want:
VBA Code:
Dim xName As Name, i As Long
For i = ActiveWorkbook.Names.Count To 1 Step -1
    ActiveWorkbook.Names(i).Delete
Next i
Thanks... I will try tomorrow morning. 6 hours away from a 5AM meeting. I'll post results after.
 
Upvote 0

Forum statistics

Threads
1,215,166
Messages
6,123,395
Members
449,098
Latest member
ArturS75

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