Thursday, March 19, 2009

How to call excel macro from java

since excel macro is vb code, since we can make a vb script file called from java and it calls excel macro

Example:
make a script file as content is

Dim objXL
Set objXL = CreateObject("Excel.Application")
With objXL
.Workbooks.Open ("File_Path")
.Application.Run "Macro_Name"
.Application.Quit
End With
Set objXL = Nothing


and save it as calling.vbs

in java you can call it as Runtime.getRuntime().exec("cmd /c start calling.vbs"); with in try,catch

Author : Anuj Patel
LinkedIn : http://www.linkedin.com/in/anujjpatel
Blog : http://goldenpackagebyanuj.blogspot.in/

No comments:

Post a Comment