I need to generate an Excel sheet from the data fetched from a database through Java. For that, I need to call some VBA Macro functions while generating that Excel. Can anyb
solution that works for me: java code:
try {
Runtime.getRuntime().exec("wscript yourPth\\myVBS.vbs");
} catch (IOException e) {
System.out.println(e);
System.exit(0);
}
myVBS.vbs script:
Set objShell = CreateObject("WScript.Shell")
Dim cur
cur = "urpath to myVBS.vbs script"
WScript.Echo cur
ExcelMacroExample
Sub ExcelMacroExample()
Dim xlApp
Dim xlBook
Dim xlsFile
xlsFile = cur & "\myExcel.xlsm"
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(xlsFile)
xlApp.Run "moduleName"
xlApp.Save
xlApp.Quit
End Sub