Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Scope of Subs?

Implicitly declared classes, which is why you don't have to New these
classes.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Norman Jones" wrote in message
...
Hi Ken,

The primary distinction here is that the ThisWorkbook, Sheet and Userform
modules are Class modules and a call to a procedure in a class module must
include the module name.


---
Regards,
Norman



"Ken Loomis" wrote in message
...
So, as I look over my VBA project, I notice that I call a module sub

from
a workbook sub without any special designation.

I assume that since this works that means that all the modules are

'under'
or 'inside of' the workbook, thus all the module subs are within the

scope
of the workbook and accessible from the workbook.

But since the workbook is a higher order object from the modules, I have
to use the "ThisWorkbook" designation to access a workbook sub from a
module.

I am just trying to get a grip on this object model stuff.

Thanks for any clarification you can provide.

Ken


"Norman Jones" wrote in message
...
Hi Ken,

Look again at my example and change:

ProjectExpired

to:

ThisWorkbook.ProjectExpired


---
Regards,
Norman



"Ken Loomis" wrote in message
...
I tried that.

Here is the workbook sub I am trying to call from a module:

Public Sub ProjectExpired()
Dim ErrorMessage As StreetLeads

ErrorMessage = "This workbook has expired." & vbNewLine
ErrorMessage = ErrorMessage & "Please contact the programmer for a
new version." & vbNewLine
MsgBox (ErrorMessage)
NewDeleteAllCode
mySave = True
ActiveWorkbook.Save
mySave = False
End Sub

Here is the call to that sub:

If IITTDH ExpTest Then
ProjectExpired
Exit Sub
End If

When I compile the project, I get a Compile error: Sub or function not
defined with ProjectExpired highlighted in the module code.

Any suggestions?

Thanks,
Ken



"Norman Jones" wrote in message
...
Hi Ken,

You can call a sub in the Thisworkbook module if the sub is declared
public.

For example:

In the ThisWorkbook module:
'-------------------------------
Public Sub Workbook_Open()
MsgBox "Hello from Workbook_Open!"
End Sub

In a standard module:
---------------------
Sub CallIt()
ThisWorkbook.Workbook_Open
End Sub


---
Regards,
Norman



"Ken Loomis" wrote in message
...
I am trying to call a sub in the workbook object from a sub in a
module, but I can't seem to make that work.

Is there a way to make that work?

TIA,
Ken













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
Name Scope Slim Slender[_2_] Excel Worksheet Functions 2 December 16th 09 01:38 AM
Scope of name Slim Slender Excel Discussion (Misc queries) 0 December 13th 09 10:01 PM
Combining two Subs Petitboeuf Excel Discussion (Misc queries) 6 April 27th 06 03:42 PM
calling subs Mike Excel Programming 4 April 8th 04 08:22 PM
Recursive Subs? ExcelMonkey[_74_] Excel Programming 5 February 5th 04 02:54 AM


All times are GMT +1. The time now is 11:07 AM.

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

About Us

"It's about Microsoft Excel"