Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just a note that this line of code:
Dim ErrorMessage As StreetLeads Should have been: Dim ErrorMessage As String And even when I fix that, I get the same error message. Ken "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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, Norman. as I am sure you're already aware, that worked.
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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ken,
Just to add, procedures in worksheet modules can similarly be called from a standard sub, providing the worksheet procedure is declared Public. E.g.: Public Sub Worksheet_Calculate() MsgBox "Hi from " & Me.Name & "Calculate" End Sub Sub CallIt2() Sheet1.Worksheet_Calculate End Sub Note that ThisWorkbook and Sheet moule procedures are Private by default. --- 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Name Scope | Excel Worksheet Functions | |||
Scope of name | Excel Discussion (Misc queries) | |||
Combining two Subs | Excel Discussion (Misc queries) | |||
calling subs | Excel Programming | |||
Recursive Subs? | Excel Programming |