ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Running macro in another workbook (https://www.excelbanter.com/excel-programming/433074-running-macro-another-workbook.html)

Gareth[_9_]

Running macro in another workbook
 
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)?

Gord Dibben

Running macro in another workbook
 
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


On Mon, 31 Aug 2009 14:56:18 -0700 (PDT), Gareth
wrote:

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)?




All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com