2

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 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

PS : via Policy => User Configuration -> Administrative Templates -> Microsoft Excel 2010 -> Excel Options -> Security -> Trust Center “VBA Macro Notification Settings”
2
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.