Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Tie 2 or More Modules Together (vba)


Can anyone tell me if there is a formula or coding that would tell one
module to reference another? I am trying to get it where when it runs
through my code and reaches a true statement then it would then go onto
the next module and do the same. I am working with several sections in
an excel worksheet so I am trying to keep my coding separate and clean.
If anyone could help I would appreciate it.

Thank You,
Chris


--
zero635
------------------------------------------------------------------------
zero635's Profile: http://www.excelforum.com/member.php...o&userid=24802
View this thread: http://www.excelforum.com/showthread...hreadid=387568

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Tie 2 or More Modules Together (vba)

From a macro in a standard module you should be able to call another macro
in a standard module.

Run "Macro1_name"

it gets a little trickier if the macro to run is in a sheet module or in
another workbook.

--
steveB

Remove "AYN" from email to respond
"zero635" wrote in
message ...

Can anyone tell me if there is a formula or coding that would tell one
module to reference another? I am trying to get it where when it runs
through my code and reaches a true statement then it would then go onto
the next module and do the same. I am working with several sections in
an excel worksheet so I am trying to keep my coding separate and clean.
If anyone could help I would appreciate it.

Thank You,
Chris


--
zero635
------------------------------------------------------------------------
zero635's Profile:
http://www.excelforum.com/member.php...o&userid=24802
View this thread: http://www.excelforum.com/showthread...hreadid=387568



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Tie 2 or More Modules Together (vba)

If you have

Module1
Sub1
Sub2

Module2
Sub3
Sub4

you should be able to call each sub(or function) from within the other
modules *unless* you prefaced the name with Private or the procedure
you're trying to call is in a Userform/Sheet/ThisWorkbook module.

e.g.

Sub IDoWork()
'can be called from within any other procedure
End Sub

Private Sub IDontWork()
'can only be called from a procedure from within the same module
End Sub




zero635 wrote:
Can anyone tell me if there is a formula or coding that would tell one
module to reference another? I am trying to get it where when it runs
through my code and reaches a true statement then it would then go onto
the next module and do the same. I am working with several sections in
an excel worksheet so I am trying to keep my coding separate and clean.
If anyone could help I would appreciate it.

Thank You,
Chris


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Tie 2 or More Modules Together (vba)

Hi Gareth,

you should be able to call each sub(or function) from within the other
modules *unless* you prefaced the name with Private or the procedure
you're trying to call is in a Userform/Sheet/ThisWorkbook module.


Provided that the worksheet. ThisWorkbook and Userform subs are declared
Public, they can be called. like any other sub, from a standard module.

For example, I put salutational Msgboxes in the Worksheet_Calculate event of
sheet(1), the ThisWorkbook Workbook_Open sub and Uerform1's click event.
Then running the following sub from a standard module. I duly received three
greetings:

Sub Tester04()
Sheets(1).Worksheet_Calculate

ThisWorkbook.workbook_open

UserForm1.UserForm_Click

End Sub

---
Regards,
Norman



"Gareth" wrote in message
...
If you have

Module1
Sub1
Sub2

Module2
Sub3
Sub4

you should be able to call each sub(or function) from within the other
modules *unless* you prefaced the name with Private or the procedure
you're trying to call is in a Userform/Sheet/ThisWorkbook module.

e.g.

Sub IDoWork()
'can be called from within any other procedure
End Sub

Private Sub IDontWork()
'can only be called from a procedure from within the same module
End Sub




zero635 wrote:
Can anyone tell me if there is a formula or coding that would tell one
module to reference another? I am trying to get it where when it runs
through my code and reaches a true statement then it would then go onto
the next module and do the same. I am working with several sections in
an excel worksheet so I am trying to keep my coding separate and clean.
If anyone could help I would appreciate it.

Thank You,
Chris


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Tie 2 or More Modules Together (vba)

Hi Norman,

I already UserForms in this manner extensively - I just didn't want to
overcomplicate things in my previous post so I omitted it (honest - it
wasn't laziness!).

I didn't know you could do the same for thisworkbook and sheet modules
however so thanks a lot for that. Very useful.

I noticed while trying it out by the way, that you don't have to
specifically declare the sub public. Presumably it's assumed public if
neither private nor public is declared - a bit like variables I s'pose.
I guess I should always be declaring one or the other rather than
leaving it to default.

Thanks - cya,
G

Norman Jones wrote:
Hi Gareth,


you should be able to call each sub(or function) from within the other
modules *unless* you prefaced the name with Private or the procedure
you're trying to call is in a Userform/Sheet/ThisWorkbook module.



Provided that the worksheet. ThisWorkbook and Userform subs are declared
Public, they can be called. like any other sub, from a standard module.

For example, I put salutational Msgboxes in the Worksheet_Calculate event of
sheet(1), the ThisWorkbook Workbook_Open sub and Uerform1's click event.
Then running the following sub from a standard module. I duly received three
greetings:

Sub Tester04()
Sheets(1).Worksheet_Calculate

ThisWorkbook.workbook_open

UserForm1.UserForm_Click

End Sub

---
Regards,
Norman



"Gareth" wrote in message
...

If you have

Module1
Sub1
Sub2

Module2
Sub3
Sub4

you should be able to call each sub(or function) from within the other
modules *unless* you prefaced the name with Private or the procedure
you're trying to call is in a Userform/Sheet/ThisWorkbook module.

e.g.

Sub IDoWork()
'can be called from within any other procedure
End Sub

Private Sub IDontWork()
'can only be called from a procedure from within the same module
End Sub




zero635 wrote:

Can anyone tell me if there is a formula or coding that would tell one
module to reference another? I am trying to get it where when it runs
through my code and reaches a true statement then it would then go onto
the next module and do the same. I am working with several sections in
an excel worksheet so I am trying to keep my coding separate and clean.
If anyone could help I would appreciate it.

Thank You,
Chris





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Tie 2 or More Modules Together (vba)


I just wanted to thank everyone for there responses. It has helped me
great deal. I am still learning this VB stuff and it is getting
little easier. Granted I am still doing some pretty ugly programming.
I think I have tripled my work though with some of the macros I hav
configured. Again, Thank You all.

Chris :) :cool

--
zero63
-----------------------------------------------------------------------
zero635's Profile: http://www.excelforum.com/member.php...fo&userid=2480
View this thread: http://www.excelforum.com/showthread.php?threadid=38756

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
Basic question - modules and class modules - what's the difference? Mark Stephens[_3_] Excel Programming 9 May 8th 05 11:48 AM
When to code in sheet or userform modules and when to use modules Tony James Excel Programming 1 December 16th 04 10:02 PM
modules tjh Excel Programming 2 November 22nd 04 04:12 PM
Modules Rich Excel Programming 1 November 4th 04 05:47 AM
Class Modules vs Modules Jeff Marshall Excel Programming 2 September 28th 03 07:57 PM


All times are GMT +1. The time now is 12:14 AM.

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

About Us

"It's about Microsoft Excel"