View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Need help with Names, please - must finish today!

Ps. I don't like to put this kind of code in the workbook_beforeclose event.

It means that I have to save for these changes to take effect--and there may be
other changes that I don't want saved.

I'll either use a dedicated macro (run it on demand) or even the workbook_open
event so that things are nice the next time someone opens the file (and macros
are allowed to run).

Dave Peterson wrote:

Maybe...

dim wks2 as worksheet
dim nm as name
set wks2 = me.worksheets("what's the name of wks2???")

for each nm in wks2.name
on error resume next
nm.referstorange.clearcontents
on error goto 0
nm.delete
next nm

This will delete names that don't refer to ranges, too!

Ed from AZ wrote:

Using Excel 2007. In a Workbook_Open sub, I set some named ranges
using
wks2.Names.Add _
Name:=nm, _
RefersToR1C1:=rg

I am trying to clear the contents of these ranges and delete the names
on Workbook_BeforeClose using
For Each nm In Me.Names
wks2.Range(nm).ClearContents
wks2.Range(nm).Delete
Me.Names(nm).Delete
Next nm

It's not working! The data is still there, and the Names Manager
shows the names still there. I've got to finish this one today. Can I
get a bit o' help, please?

Ed


--

Dave Peterson


--

Dave Peterson