Using a Macro from one workbook within another

G

Guest

Hello.

Here's the scenario... I have one workbook open and I copy specific sheets
into a new woorkbook, now both have the same macros in them, what I want to
do is use woorkbook1 to switch control to workbook2 and run a macro that is
in workbook2.

For example: Workbook1 code...

Private Sub CommandButton1_Click()
'Select Tabs and Copy
Sheets(Array("Info", "Data")).Copy

'Save New Workbook
ActiveWorkbook.SaveAs Filename:="WorkBook2.xls", FileFormat:=xlNormal,
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
CreateBackup:=False

Windows("WorkBook2.xls").Activate

'Use Macro That's In WorkBook2
Call DoThis(WorkBook2.xls)

End Sub

Here's the Code in WorkBook2.xls:

Sub DoThis()
WorkBooks("WorkBook2.xls").Close
MsgBox("All Done Boss.")
End Sub


Any Ideas on this?

Thanks in Advance.
Rob
 
G

Guest

If your workbooks have the same macros in them, wouldn't it be as well to
run the macro DoThis() from workbook1?
 

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