View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Macro needs updated Range name addresses

Revenue has brought this to us :
ActiveWorkbook.Names.Add Name:="Current", RefersTo:=Selection.Address


Before I saw this, I actually got it to work without the .address
after selection. Is there a danger in not putting the .address in
there?
Or, is that the difference you meant is that way would cause a
workbook level names?

Thanks,


Bruce


Selection returns an absolute address of its range object anyway and so
it's not really needed. HOWEVER, it would be 'good practice' to include
it as it helps document exactly what the code is doing.

This has nothing to do with workbook level names. any defined name that
excludes to syntax I posted for 'attaching' the name to a worksheet
will default to global scope. This is also considered 'good practice'
to NOT use global scope unless absolutely necessary. Just to
demonstrate the difference between global scope and local scope for
defined names...

Workbook1 has Sheet1 and Sheet2, both created from a template for
generating invoices.

Defined name ("InvNum") range on Sheet1 for Invoice# is local scope.
Defined name range ("InvNum") on Sheet2 for Invoice# is local scope.

Next invoice generated will also have a local scope defined name
("InvNum") for Invoice#, as will every sheet inserted using this same
template. You can't do this will global scope names because a 'name
conflict' exception will occur each time you try to insert another
sheet from that template. Having names use local scope avoids any 'name
conflict' exceptions. Since it's common to copy/move sheets from one
workbook to another, some discipline needs to be implemented when using
defined names so conflict exceptions don't screw up all your hard work!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion