3 Replies Last post: Aug 19, 2008 4:21 PM by Serge Piletsky  
Heinrich Wendel   7 posts since
Aug 14, 2008
Currently Being Moderated

Aug 14, 2008 11:34 AM

Disable Macros

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

Igor Novikov TeamDev Ltd. 225 posts since
Apr 24, 2006
Currently Being Moderated
1. Aug 15, 2008 5:33 PM in response to: Heinrich Wendel
Re: Disable Macros

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

Serge Piletsky TeamDev Ltd. 670 posts since
Apr 24, 2006
Currently Being Moderated
3. Aug 19, 2008 4:21 PM in response to: Heinrich Wendel
Re: Disable Macros

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

More Like This

  • Retrieving data ...