Hi,
Is there a way to disable Macros when opening a Workbook. I only want to automate some tasks via JExcel and don't wan't to pop the Macros up when opening the file.
regards,
Heinrich Wendel
Hi Heinrich,
You can disabling macros by following way:
application.getPeer().setAutomationSecurity(new MsoAutomationSecurity(MsoAutomationSecurity.msoAutomationSecurityForceDisable));
Please note that this action should be run in OleMessageLoop:
Runnable runnable = new Runnable()
{
public void run()
{
application.getPeer().setAutomationSecurity(new MsoAutomationSecurity(MsoAutomationSecurity.msoAutomationSecurityForceDisable));
}
};
try
{
application.getOleMessageLoop().doInvokeAndWait(runnable);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
Please try this suggestion and let us known the results.
Sincerely,
Igor Novikov
Hi Heinrich,
I think the problem is that Igor has used the Excel API types which are not present in the original JExcel library. That's why you could not build the sample. This MsoAutomationSecurity class is available in separate msexcel.jar library, which contains the wrappers for all types of MS Excel COM type library. You can download this package from our ftp side: ftp://ftp.teamdev.com/updates/msexcel.jar
Also, you can download the JExcel v1.2 JAR with complete set of wrappers from our site: http://www.teamdev.com/downloads/jexcel/jexcel-1.2-full.jar
As to your question about running the code in OleMessageLoop. That's required in order to avoid COM marshaling exception which can occur when you working with MS Excel functionality in different Java threads.
Please try this solution and let me know the results.
-Serge