View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Declaring as Object rather than Excel.Worksheet

Hi,
Yes, maintaining references.
If you use the "ByVal Sh As Excel.Worksheet" method (early binding) you have
to set a reference to Excel and therefore a specific version of Excel. Which
should work with equal or a higher version number on the users machine.

"ByVal Sh As Object" dynamically creates an Excel object if it is installed
on the users machine, and is known as late binding. Late binding can have
problems also. If you use a command that didn't exist in previous versions
it will error.

You can also programmatically create a reference to whatever version is
installed on the users machine, (with lots of error checking) and get the
best of both methods.
If you do a google search you should find some examples of programmatically
creating a reference.

--
John
johnf 202 at hotmail dot com


"R Avery" wrote in message
...
| Why would anyone prefer declaring a variable as object rather than
| explicitly declaring what type of object it is (assuming it will always be
| the same in the end)?
|
| For example, in workbook events, why is it "ByVal Sh As Object" rather
than
| "ByVal Sh As Excel.Worksheet"?
|
| Is it a problem with maintaining references, or...???
|
| Thanks!
|
|