How to call macro from other workbook

P

ppyxl

Hi,

I m running a macro from one of the excel workbook let s say workbook1
i want to add a call macro code so that i can execute the macro in othe
workbook2.

Guys, do u have any idea/

Thanks,
ppyx
 
B

Bob Phillips

Application.Run "book2.xls!test_msgbox"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
P

ppyxl

code is not working, pls check for me. Many thanks
____________________________
Sub SaveFO2()

-'define date-

Dim ReportDate, LsReportDate As Date
Dim ReportName, directoryName As String

LsReportDate = Workbooks("startup").Sheets("FO2").Range("B2")
ReportDate = Workbooks("startup").Sheets("FO2").Range("B3")

-'save from one file to another-

Workbooks.Open fileName:=("K:\Reporting\XL\DataBase\FO2 "
Format(LsReportDate, "yyyymmdd") & ".xls"), updatelinks:=0

ActiveWorkbook.SaveAs "K:\Reporting\XL\DataBase\FO2 "
Format(ReportDate, "yyyymmdd") & ".xls"

-'define some strings-
directoryName = "K:\Reporting\XL\DataBase\FO2 " & Format(ReportDate
"yyyymmdd")
ReportName = "FO2 " & Format(ReportDate, "yyyymmdd") & ".xls"

Sheets("Input_Working").Activate
Cells(2, 4).Value = ReportDate

-'run macro-
Application.Run ReportName!Main

End Su
 
P

ppyxl

Hi, thanks!

error msg still! macro not found

is it any speical setting for the macro in another excel work book
 
G

Guest

the macro should be in a general module and not in a sheet module or the
thisworkbook module. the macro should be public, but this is the default.
 
B

Bob Phillips

Try

Application.Run "'" & ReportName & "'!Main"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

Good catch on Bob's part - Spaces in a workbook name require the name be
enclosed in single quotes.
 

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