LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Breaking User Form Code into modules question

copy all of the code below to a public code module, thin run Sub Main()

Sub Main()
proc1
proc2
proc3
proc1
MsgBox "Notice that proc1 ran twice"
End Sub

Sub proc1()
x = InputBox("Enter a name", "NAME")
MsgBox x & " was entered for a name."
End Sub

Sub proc2()
MsgBox "This is second procedure"
End Sub

Sub proc3()
MsgBox "This is third procedure"
End Sub






"Brian" wrote in message
...
Lets say I take a really big Sub Procedure that is in the User Form Code
Window and break it down into 6 smaller subs and put the 6 subs into a
module.

Now I have 6 Small Subs sitting there in a module. In place of the Big Sub
Procedure can I put a call statement there to call the Smaller Subs?

Can I just call the entire module to run or do I need to call each Smaller
Sub to run 1 at a time. I assume they will run in the order they are in.
Is
this the same as example you gave me?

Module1
Sub1
Sub2
Sub3


Located in the Main User Form Code Window
-----------------------------------------------------
Sub Main()
Macro1
MsgBox "Macro1 Completed"
Macro2
MsgBos "Macro2 Completed"
Macro3
MsgBox "Program Completed"
End Sub


Located in the Module
-------------------------------------------
Sub Macro1()
'Declarations
'Variable assignment
'Code body
End Sub

Sub Macro2()
'Same pincipal as Macro1
End Sub

Sub Macro3()
'Same principal as Macro1
End Sub

Did I get it correct or am I still missing something?









"JLGWhiz" wrote:

P.S. If you need to call an event procedure from outside its host object
(i.e. UserForm or Sheet) then you probably did not need an event
procedure
to begin with. It should have been written as a public Sub procedure and
then called by the event code if needed for the event, instead of the
reverse of trying to call an event procedure from a public code window.


"Brian" wrote in message
...
I was hoping to make all the modules Private Sub. I do not want them
being
changed after I am done.

All the subs in the User Form are are Private. Can I just cut and paste
them
into a module and then in User Code Window call that Sub.

Private Sub Update_Installer_Forms_10_Click()
Call Update_Installer_Forms_10_Click() 'Macro1 located
in
Module1
End Sub


"JLGWhiz" wrote:

Hi Brian,

1: My question is in the UserForm Code Window how do I refer to a
module?

A1: You can call any procedure that is in the public modules
(Module1,
Mocule2, etc.) from the UserForm code module. If you are using event
code
to respond to some user's interaction, then in the event code you
would
call
the working procedure out of the public module:

Private Sub Listbox1_Click()
Call Macro1 'Macro1 located in Module1
End Sub

2: If the Code is to large can one Module call another module?
Something like User form Code calls Module 1 and at the end of
module
1
code, it calls for module 2, etc...

A2: Yes, any public module can call from and respond to any other
public
module.
..
3: Most of my Code is With statements / End With then more code.

A3: So? That is just a style of writing code. I do not believe
it
would influence whether the code can be called from another module or
not.

As a general rule, private procedures can call any public procedure,
but
the
reverse is not necessarily true.


"Brian" wrote in message
...
I have a user form with alot of code in it. As of now all the code is
in
the
Userform
Code window, but there is so much code that it's getting confusing.
I
have
one Sub that is to large and needs to be split into several subs.

When I was done I was going to break all the Subs down into
different
modules to clean it up. I guess I will have to do that now, but I am
not
sure
how to do it.

1: My question is in the UserForm Code Window how do I refer to a
module?
2: If the Code is to large can one Module call another module?
Something like User form Code calls Module 1 and at the end of
module 1
code, it calls for module 2, etc....
3: Most of my Code is With statements / End With then more code.


Here is an Example of the Code in the UserForm Code Window:
Private Sub Update_Installer_Forms_10_Click()

With Workbooks("Master Installer Forms.xlsm").Sheets("Install Pack
Con")
**Code for the sub is here**
End With

With Workbooks("Master Installer Forms.xlsm").Sheets("Install Chk
List")
**Code for the sub is here**
End With

End Sub

I really need to sort this out so it's not so confusing to work on.
Can
anyone please help me or explain it in english to me.



.



.



 
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
List Modules in a user form Rob Excel Programming 2 September 20th 07 04:20 PM
VBA & User Form modules vanish Pete[_27_] Excel Programming 6 July 10th 06 03:16 AM
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
Scope of variable includes all Form _and_ Code modules?? John Wirt[_2_] Excel Programming 5 August 18th 03 08:27 AM


All times are GMT +1. The time now is 02:03 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"