PDA

View Full Version : copy a module from one workbook to another via code



drawworkhome
12-06-2009, 02:44 PM
i am looking for some guidance on copying a sub routine ("checkrange" in workbook (a)) to the same place in a new workbook i create.
the steps i am looking for is:
1. create a newworkbook (b)--this is up and running
2. copy 2 sheets from another workbook (a)--this is up and running also
3. copy sub routine (checkrange)from workbook a to workbook b
4. carry on with what i am trying to accomplish--yet to be written......

i am a newbie, so not sure what hurdles i need to jump over.
any input is greatly appreciated.
e
ps, found this link and will try and work this:
http://www.cpearson.com/excel/vbe.aspx

lucas
12-06-2009, 03:25 PM
I'm short on time but you can check out this thread:

http://www.vbaexpress.com/forum/showthread.php?t=6125&highlight=copy+sub+module

post #7 especially.......You can probably find more by searcing the forum.

Bob Phillips
12-06-2009, 03:26 PM
You need to allow Trusted Access to Visual Basic Project to be able to write to the VBE.

The simplest way is to put that sub in a separate module, expoort the module from the one workbook, import it into another, and then kill it.

drawworkhome
12-06-2009, 03:28 PM
thank you all.
i will enjoy damaging the wall with my head on this one.
stay tuned....

drawworkhome
12-06-2009, 04:32 PM
do i need to set a reference to anything, like vbaproject?

GTO
12-06-2009, 05:14 PM
By memory/not tested, but I seem to recall VBIDE being necessary.

drawworkhome
12-06-2009, 05:54 PM
man, where does a guy go to learn all this??
first filescriptobject and now this....
is there a book or something that puts this all together?
btw, thanks for the tip gto, hope your staying warm down yonder way.
erik
also, can you have to many references set? maybe take a performance hit from this?

Bob Phillips
12-07-2009, 01:19 AM
do i need to set a reference to anything, like vbaproject?

I never do, never have had to.

Bob Phillips
12-07-2009, 01:21 AM
man, where does a guy go to learn all this??
first filescriptobject and now this....
is there a book or something that puts this all together?
btw, thanks for the tip gto, hope your staying warm down yonder way.
erik
also, can you have to many references set? maybe take a performance hit from this?

Most of those references are set by default, Excel will load them as it needs them.

GTO
12-07-2009, 02:28 AM
Dang it and shame on me. Knew I shoulda checked before opening my big yap.

Sorry about that drawworkhome.

drawworkhome
12-07-2009, 08:22 AM
no worries. all part of learning this stuff.
i hope to make this my occupation one day....

Bob Phillips
12-07-2009, 08:36 AM
Me too :think:

lucas
12-07-2009, 08:43 AM
GTO, don't beat yourself up over that. I do it all the time.

We give the best info we can and if there are better or more correct ways, well thankfully, Bob, Malcolm and others are here.

Usually, the more discussion, the better.

drawworkhome
12-07-2009, 07:32 PM
well, for the record, i appreciate all the help. this forum is by far the best i have found. you guys are great and there is always more than one way to skin a cat.....
thanks!!!