Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run code in other open book? WB.VBproject.VBcomponents.CodeModule. . . 1

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Is there a way to run a code module in another workbook which is already open in Excel but is not an add-in and has no VBE reference? (There are reasons why I don't want to do either of these, but the explanation is rather long-winded so I'll omit it).

I have a feeling the answer is no (which is fine - I don't need it, but it'd make a nice touch in this one project), but thought I'd ask in case anyone knew a way.

Something using the likes of . . .
Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("NewModule").CodeModule
StartLine = .ProcStartLine("TargetProcedure", vbext_pk_Proc)

and somehow executing that procedure...?
 
If I understand your question . . .

If you have 2 xl files open: Book1.xls & Book2.xls. Book2.xls has a sub called MainSub that you want to run from Book1.

In your code in Book1, make sure that Book1 is activated.
Then the following line will run Mainsub:
Application.Run "Book2.xls!MainSub"

You can also run a function in Book2 the same way using:
ReturnVal = Run("Book2.xls!MainFunction", Arg1, Arg2)

Hope it helps

Rog
 
That's what I'm lookin for, thanks Rog!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top