Use more than one module

G

Guest

Hi, I think I'm missing something here, and once again, VBA help is less than
helpful. Basically, my code is now too big for one module, so I want to split
across two (or more). I can't imagine this isn't possible, but can someone
fill me in on how it's done?

Thanks
 
T

Tim Williams

Add a new module (right click on the project in the VBE and add>>module) and move some of your procedures to the new module (it's
not just one big procedure, right?)
 
G

Guest

You mean adding a second module. Right Click on the Module that you have and
select Insert -> Module. Cut some of the procedures out of your original
module and paste them in the new module. Try to orgainze your procedures
logically. Put all of one type of procedure in one module. For instance put
all of your formatting procedures in one module and all of your save
procedures in another.
 
G

Guest

Hi Jim

Thanks, got that all sorted, but how do I keep it running once it gets to
the end of the 1st module?
 
G

Guest

So you have one Really Big Procedure??? If so then you want to break that
procedure up into it's logical sections and call it kind of like this...

Sub DoLotsOfStuff()
Call DoThis
Call DoThat
Call DoSomethingElse
end Sub

Sub DoThis()
'Some of your Code here
end sub

Sub DoThat()
'Some More of your Code here
end sub

Sub DoSomethingElse()
'Still yet more code here
end sub
 
G

Guest

OK, it is one big procedure but this is primarily because I'd have no idea
how to run the next part of what I wanted to do once the first procedure had
finished without having to manually run it myself, which isn't ideal. Also
when I started it the concept was a bit simpler, and it's got a bit more
complicated as it's progressed. It's very easy to split into several
procedures if one of you could let me know how to keep it running once it
gets to the end.
thanks
 
B

Bob Phillips

Call Macro2

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
T

Tim Williams

sub ReallyLong()

dosomething1
dosomething1
dosomething1
dosomething1
dosomething1
 
T

Tim Williams

Premature send. Your one long procedure:

sub ReallyLong()
dosomething1
dosomething2
dosomething3
dosomething4
dosomething5
dosomething6
end sub

becomes


sub ShorterOne()
dosomething1
dosomething2
dosomething3

ShorterTwo
end sub

'and in the other module....
sub ShorterTwo()
dosomething4
dosomething5
dosomething6
end sub

Tim
 
G

Guest

Well, how simple is that then? Guess that's why they call it basic!! Thanks
very much, there's a piece of information that will be very helpful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top