View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff[_2_] Harald Staff[_2_] is offline
external usenet poster
 
Posts: 449
Default Why does variant not need set?

Hi Walter

Afaik a Variant is a pointer, to "anything", where many things are objects
and many will be something different. So Set makes sense maybe half of the
times. No error, a pointer does not need Set, by design.

MS doesn't care much about VB6 since the last millennium celebration and the
sometimes Set sometimes not logic is eliminated in VB.NET If I remember
correct.

HTH. Best wishes Harald

"Walter Briscoe" wrote in message
...
I am running VBA 6.5 from Excel 2003.

I have a line like Foo = Range(Cells(1, 1), Cells(1, 2))

If Foo is declared with Dim Foo As Variant, the line runs without error.
If Foo is declared with Dim Foo As Range, I get "Run-time error '91';

Object variable or With block variable not set".

I can fix the assignment by prefixing it with Set to read
Set Foo = Range(Cells(1, 1), Cells(1, 2))

Why does a variant not need Set and a compatible object needs set?

I don't imagine anyone outside Microsoft can give the reason for such
errors not being detected at compilation time. ;)

[I am in the middle of eliminating Variant, where possible in a fairly
large file. I have already applied early binding where possible]
--
Walter Briscoe