tags:

views:

920

answers:

2

How can I run excel from command line / cmd script such that it doesn't prompt if I want to enable macros in the spreadsheet I am running it with?

A: 

The prompt is an Excel settings so you'll need to go into Excel and change the security settings. You can change it in Excel 2007 through the Excel Options -> Trust center -> Trust center settings -> Macro Settings.

I don't know of a way to disable this through the command line, and I don't think it makes sense that you could, sounds like a security breach to me.

Tamar
It is hard to imagine some damage you could do from Excel that you couldn't already do from the command line. If you run process monitor and adjust that setting, you could probably find out which registry value(s) control the macro prompt and change it in the cmd file before launching Excel.
JimG
That's a good point. However keep in mind that this is an Excel setting, not specific to a single document. Does it makes sense to you that a program you're running will change your Excel security settings, even if it can?
Tamar
It's all about the context really. It makes sense to me that a program might change my Excel settings if that's what I intended it to do. It obviously makes less sense if it's a program someone else wrote that I am running unawares (though in this case, security is already well out the window). I envision Grzenio doing this on his own machine, or possibly on company-owned equipment - mostly because I can't see someone honestly trying to get unsuspecting users to open a document via a batch file.
JimG
Yes, but even if it's for a company internal, it will change the security settings for all the users. This means that even if the files the command line opens are ok, in the future there will be no check on macros (unless it is switched back after running the program)... Every macro any user will get will then run automatically.
Tamar
+1  A: 

Signing your macros with a digital signature may do what you want. If you've signed the macros in a spreadsheet, then a user who opens it is prompted:

"Foo.xls" contains macros by Acme Software, Inc. Macros may contain viruses. It is usually safe to disable macros, but if the macros are legitimate, you might lose some functionality.

The user will get the usual Disable / Enable Macros choice, but she will also get a bonus option:

Always trust macros from this publisher.

If the user selects that option, she will never see the prompt again for this file or any other signed by the same publisher.

Here are instructions on how to get a certificate and sign an Excel 2007 file. If you're using Excel 2003, read that and then read these instructions on signing an Excel 2003 file.

Don Kirkby