Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Declaring as Object rather than Excel.Worksheet

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!


  #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!
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Declaring as Object rather than Excel.Worksheet

Jaf

I had a problem last year where I declared wsMenu as Worksheet

When I tried to set a variable based on a option button value I was
getting an error. To overcome this I had to declare wsMenu as Object -
Early binding as against late binding


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Declaring as Object rather than Excel.Worksheet

R

The reason that it is declared as Object in the events is that Sh can refer
to more than one kind of object. Sh can refer to a Worksheet or a
ChartSheet (and probably to an xl4 macro sheet), so they have to declare the
variable as the generic object so that the event works for worksheets and
charts.

There is no Sheet object, so they can't use that. But there is a Sheets
collection object which contains all the different kinds of sheets.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"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!




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
Excel 2002 and VB declaring number as double Gary Excel Discussion (Misc queries) 2 March 5th 09 03:43 AM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Charts and Charting in Excel 3 August 24th 06 07:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Excel Discussion (Misc queries) 2 August 24th 06 05:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet jeftiong New Users to Excel 0 August 23rd 06 01:50 PM
Linking an object in power point to a excel worksheet jth Excel Discussion (Misc queries) 3 July 24th 05 02:16 AM


All times are GMT +1. The time now is 03:16 PM.

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

About Us

"It's about Microsoft Excel"