I have a Powershell script that creates an Excel File, and within that runs a macro to embed an OLEObject. This is going to be used by field engineers and therefore on different computers. To run the script, the macro settings need to be set to "Enable all macros..." and "Trust access to the VBA project object model." Is there any way this can be incorporated into the Powershell script? Ideally to be activated and then deactivated at the end. I suspect this is something that can't be automated, and will need to be done manually to run the script. Any suggestions would be much appreciated.
2 Answers
The run method can be used to run either a macro or a function.
$app = $excel.Application
$app.Run("Macro_1")
$app.Run("Macro_2")
$app.Run("Macro_3")
To enable/disable via Regedit :
Registry Key to change:
[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Security]
"VBAWarnings"=dword:00000001
Registry Option Values:
•1 = Enable all macros (not recommended; potentially dangerous code can run)
•2 = Disable all macros except digitally signed macros
•3 = Disable all macros with notification
•4 = Disable all macros without notification
1 Comment
expirat001
PS : via Policy => User Configuration -> Administrative Templates -> Microsoft Excel 2010 -> Excel Options -> Security -> Trust Center “VBA Macro Notification Settings”