View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Adding Name object to a collection does not add an object

The parenthesis makes excel want to "evaluate" what's inside them. And that
means that tmpname gets passed as just the name (tmpname.value which would
evaluate to something like: =sheet1!$a$1).

So in one case (with the parens) you're passing a bunch of strings to the
collection. In the other (without the parens), you're passing real name
objects--and all their properties.

Kind of close to the difference between

Dim myVal As Variant 'not range!
myval = activesheet.range("a1:a10")
'or
set myval = activesheet.range("a1:a10")

The top creates a 10 row by 1 column array of values.
The bottom assigns a range object to A1:A10. And all those properties are still
available.

(kind of...)

Tim Richardson wrote:

Dave Peterson wrote:
Drop the ()'s around the (TmpName) in the .add line and it'll work ok.


thanks. That worked. But why does this fail:
"myCollection.Add (tmpName) "

and why does this work?
myCollection.Add tmpName


--

Dave Peterson