Reputation: 1653
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.
Upvotes: 1
Views: 15038
Reputation: 292
New-ItemProperty -Path Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Excel\Security -Name "VBAWarnings" -Value "3" -PropertyType DWORD -Force | Out-Null
Based on the previous answer, I added the powershell command to enable run excel macros via the registry
Upvotes: 2
Reputation: 2215
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
Upvotes: 3