View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
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!