This is a java code snippet which will run VB script (.vbs file) which in turn
will run an excel macro.
1. The excel macro called "Macro3" is embedded in "Raj.xls". This macro will find the first empty row and print "Java Tutorial" for 10 times.
2. There is a vb script file callef 'Raj_vbs.vbs' which will open the excel file and run the macro embedded in it.
3. This vb script will be executed from java using the command 'Runtime.getRuntime().exec("cmd /c Raj_vbs.vbs");'
How to use?
------------------
1. Save the excel file in your desktop.
2. Save the vbs file in your desktop (open the vbs and make sure the path of the excel file is right).
3. Save the Java file in your desktop.
4. Compile the java class
5. Execute the java class.
6. Open the excel file and check whether the macro got executed.
1. The excel macro called "Macro3" is embedded in "Raj.xls". This macro will find the first empty row and print "Java Tutorial" for 10 times.
2. There is a vb script file callef 'Raj_vbs.vbs' which will open the excel file and run the macro embedded in it.
3. This vb script will be executed from java using the command 'Runtime.getRuntime().exec("cmd /c Raj_vbs.vbs");'
How to use?
------------------
1. Save the excel file in your desktop.
2. Save the vbs file in your desktop (open the vbs and make sure the path of the excel file is right).
3. Save the Java file in your desktop.
4. Compile the java class
5. Execute the java class.
6. Open the excel file and check whether the macro got executed.
import java.lang.Runtime; import java.lang.Process; import java.util.*; public class CallExcelMacro { public static void main(String[] args) { try{ Runtime.getRuntime().exec("cmd /c Raj_vbs.vbs"); }catch(Exception e) { System.out.println(e);} } }