View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Efficient use of sheet "codenames"


BBB (Sheet3) ' error message - Object doesn't support this property or
message.


When you enclose the sheet parameter within parens, you are causing
VBA to evaluate the item to its default value, and a worksheet has no
default value. Since there is no default value, you get the "object
doesn't support..." error.

You'd get the same result regardless of whether you pass by code name
or by sheet name. E.g,

BBB (Worksheets("Sheet1"))

will cause the same error.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Sun, 13 Dec 2009 14:25:46 -0700, "Robert Crandal"
wrote:

So, when I call BBB, I must call it as follows:

BBB Sheet3 ' works okay

On the other hand, I get an error message if I call it as follows:

BBB (Sheet3) ' error message - Object doesn't support this property or
message.

I just think it's weird that an error occurs if I place parentheses around
Sheet3. I wonder
why that causes an error?

Anyways, thank you so much for your help. Your solution above DOES work
for my needs!


"Chip Pearson" wrote in message
.. .

Declare the parameter As Worksheet. E.g,

Sub AAA()
BBB Sheet3
End Sub

Sub BBB(WS As Worksheet)
Debug.Print WS.Name, WS.Range("A1").Text
End Sub