WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Run an Excel Macro

 Keywords: Run Execute Excel Macro 

Question:

I am pretty much new to Winbatch and am trying to run an excel macro from Winbatch. Should I use DDE or OLE and does anyone have any sample code? Thanks.

Answer:

This seems to work for me:
macroname = "MyMacro" ;Specify valid macro name

cXLS = AskFileName("Select Excel WorkBook",".\","Excel Files|*.xls|","*.xls",1)

DB             = ObjectOpen("Excel.Application")
DB.Visible     = @TRUE
DB.UserControl = @TRUE
oAPP = DB.Workbooks
oAPP.Open(cXLS)

;"sample.xls!MyMacro"
runme = StrCat(FileRoot(cXLS),".",FileExtension(cXLS),"!",macroname)
mySum = DB.Run(runme)
Message( "Macro result: ",mySum)


oAPP.Close()
ObjectClose(oAPP)
DB.Quit()
ObjectClose(DB)
Exit

Article ID:   W15641
File Created: 2003:05:13:11:29:20
Last Updated: 2003:05:13:11:29:20