View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default An Interesting vba Excel quirk

Since you define Departments in the module as a worksheet object
variable, the compiler looks for a Worksheet method named Dtest, and
doesn't find one.

One workaround would be to define Departments in the module as an Object:

Public Departments As Object

so that the Dtest method won't be checked until run-time.

Another (IMO better) way would be to forget the variable altogether and
change the "Departments" worksheet's code name to Departments (via the
VBA Properties window).




In article ,
GeorgeJ wrote:

Hello,

Im my workbook I have a sheet named "Departments". In the code for this
sheet I have the following

sub DTest
msgbox "Hello from DTest"
end sub





My code in Module 1 includes the following

Option Explicit
Public Departments as worksheet

pubilc sub setup
Set Departments = activeworkbook.sheets("Departments")
end sub

sub Test1

setup

Departments.DTest

end sub

When I try to complie this code, VBA insists on interpreting

Departments.Dtest

as a method of the object variable Departments rather than a reference to
the routine DTest found on the code for the sheet named Departments. So an
error is generated. Casn anyone think of a way around this preblem?

Thanks