Running macro in another workbook

G

Gareth

Am not a VBA power user but was wondering if someone could help. Does
anyone have code for opening a workbook(2) from another workbook(1)
and then running a macro in workbook(2)?
 
G

Gord Dibben

In workbook(1) enter this in Thisworkbook module.

Edit for path and filename, of course.

Private Sub Workbook_Open()
Workbooks.Open Filename:= _
"C:\Program Files\Microsoft Office\Exceldata\12months.xls"
End Sub

In workbook(2) enter this in a general module

Sub hoohah()
msgbox "hello hoohah"
End Sub

In Thisworkbook module enter

Private Sub Workbook_Open()
hoohah
End Sub

Close and save both workbooks.

Open workbook(1) and see what happens.


Gord Dibben MS Excel MVP
 

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