通过Powershell启用宏

通过Powershell启用宏

本文介绍了通过Powershell启用宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Powershell脚本来创建一个Excel文件,并在其中运行一个宏来嵌入一个OLEObject。这将由现场工程师使用,因此将在不同的计算机上使用。要运行脚本,宏设置需要设置为启用所有宏...和信任对VBA项目对象模型的访问。
有什么办法可以并入Powershell脚本吗?理想地被激活,然后在最后停用。
我怀疑这是无法自动化的,需要手动完成才能运行脚本。
任何建议将不胜感激。

解决方案

运行方法可用于运行宏或函数。

  $ app = $ excel.Application 
$ app.Run(Macro_1)
$ app .Run(Macro_2)
$ app.Run(Macro_3)

通过Regedit启用/禁用:

 注册表项更改:
[HKEY_CURRENT_USER\Software\Microsoft\Office \14.0\Excel\Security]
VBAWarnings= dword:00000001

注册表选项值:
•1 =启用所有宏(不推荐;潜在的危险代码可以运行)
•2 =禁用除数字签名的宏之外的所有宏
•3 =禁用所有宏,通知
•4 =禁用所有宏,而不通知


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.

解决方案

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

这篇关于通过Powershell启用宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:04