Excel command line

Asator

Board Regular
Joined
Apr 5, 2010
Messages
186
Are there any command line switches for excel that would cause it to run while suppressing the "Allow macro?" diaglog box (defaulting to No), open and print specified file, and close?

I'm currently using shellexecute to print excel files, but it requires user interaction for workbooks that have macros. I'd like to get rid of that prompt (obviously without lowering their security settings).

Any ideas?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I think (not sure) that the /safemode switch will prevent macros from running.

If that doesn't work, you could instead open the workbook in VBA after disabling events to prevent macros from running.

If you need events enabled when the code runs, you can open the workbook in a separate instance of Excel after setting Application.AutomationSecurity to msoAutomationSecurityForceDisable
 
Upvote 0
This was a lot easier than I expected. Only took 4 lines of code.

I already have an excel instance open from my VBA, so I just turned off security in that instance, opened the workbook, printed, closed it.

For those curious:
Code:
Dim xlApp As Object
 
...
 
'Create ActiveX connection to Excel, turn off security warnings (block macros)
Set xlApp = CreateObject("Excel.Application")
xlApp.AutomationSecurity = msoAutomationSecurityForceDisable
 
...
 
Case ".xls", ".xlsx", ".xlsm", ".xlsb"
    xlApp.workbooks.Open (rtFolder & sender_folder & "\" & dStr & "\" & AttFileSaveName)
    xlApp.workbooks(AttFileSaveName).PrintOut
    xlApp.workbooks(AttFileSaveName).Close False
    pCount = pCount + 1
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top