#1   Report Post  
Posted to microsoft.public.excel.misc
Jeff
 
Posts: n/a
Default Using "Set" variable

I was looking over the "Set" variable in the help.

It gave the example:

Dim YourObject, MyObject, MyStr
Set MyObject = YourObject ' Assign object reference.
' MyObject and YourObject refer to the same object.
YourObject.Text = "Hello World" ' Initialize property.
MyStr = MyObject.Text ' Returns "Hello World".
' Discontinue association. MyObject no longer refers to YourObject.
Set MyObject = Nothing ' Release the object.

When should you use this? Does it have any advantage over just assigning
MyObject = "Hello World"

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Using "Set" variable

You have to use when referring to an object, e.g.

Set MyObject = Range("A1")

In the case MyObject will be a range variable that points to A1 and so you
can access any of the properties of that object via the range variable, such
as

MyObject.Font.Bold = True

If you are not referring to the object but a property of it that object, you
would not use Set, such as

MyValue = Range("A1").Value

In this case MyValue just contains the value in cell A1, and you do not have
access to an of the other properties of A1.

So, it is horses for courses.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Jeff" wrote in message
...
I was looking over the "Set" variable in the help.

It gave the example:

Dim YourObject, MyObject, MyStr
Set MyObject = YourObject ' Assign object reference.
' MyObject and YourObject refer to the same object.
YourObject.Text = "Hello World" ' Initialize property.
MyStr = MyObject.Text ' Returns "Hello World".
' Discontinue association. MyObject no longer refers to YourObject.
Set MyObject = Nothing ' Release the object.

When should you use this? Does it have any advantage over just assigning
MyObject = "Hello World"

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Aling multiple sets of data by header column MarkusO Excel Discussion (Misc queries) 2 April 12th 06 07:29 PM
Variable Names in Formulas Paulo Excel Discussion (Misc queries) 2 March 29th 06 01:16 PM
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
object variable or with block variable not set Diego Excel Discussion (Misc queries) 1 August 9th 05 02:46 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"