View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_8_] Nigel[_8_] is offline
external usenet poster
 
Posts: 172
Default Object variables

You must declare each vars explicitly....

Dim ObjVar1, ObjVar2 As Object

results in ObjVar1 being set to Variant; and ObjVar2 as an Object

Use:

Dim ObjVar1 As Object, ObjVar2 As Object


Cheers
N

"scarbrough" wrote in message
news:UGdAb.68591$m24.26909@fed1read02...
I ran into a proble trying to set a declared object variable to a value,
like this:

Dim ObjVar1, ObjVar2 As Object

With Range("MyRange")
Set ObjVar1 = .Find(x)
ObjVar2 = ObjVar1.Address
End With
Range(ObjVar2).Activate

The problem has to do with the fact that the second object variable was

set
to Nothing by default, and I don't know how to set it to Empty which is

what
I have to do to in order to get it to accept a value. I've gone around

the
problem by setting it to a Variant data type, and I know I can go around

it
by not declaring it in the first place, but I am curious to find out why
ObjVar1 in the declaration statment is set to Empty and ObjVar2 is set to
nothing, try this:

Paste this code into VBA and step into it. Look at the value of

objMyObject
and objMyObject1 and explain to me why they are not both Empty.

Sub test()
Dim objMyObject, objMyObject2 As Object
End Sub

Thanks











----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---