1
我想使用VBScript從MS Word模板中刪除所有的vba模塊。我寫了下面的腳本。使用VBScript刪除MS Word宏
const wdDoNotSaveChanges = 0
WScript.Echo "starting Word..."
Dim oApplication, doc
Set oApplication = CreateObject("Word.Application")
WScript.Echo "opening template..."
oApplication.Documents.Open "path\to\test.dot"
Set doc = oApplication.ActiveDocument
Dim comp, components
Set components = oApplication.ActiveDocument.VBProject.VBComponents
For Each comp In components
components.Remove comp
Next
WScript.Echo "exiting..."
doc.close wdDoNotSaveChanges
oApplication.Quit wdDoNotSaveChanges
當運行VBA模塊中的話,那工作在類似的代碼,但是當我運行此VBScript中,我得到這個錯誤:test.vbs(14, 2) Microsoft VBScript runtime error: Invalid procedure call or argument
你爲什麼不從VBA中刪除它? – 2010-02-26 15:10:44
您是否授予訪問VBA項目的權限?這是通過宏安全設置下的複選框(「信任訪問VBA項目對象模型」)完成的。 – 2010-02-26 15:23:56
@irwin:因爲我想從Ant腳本執行此操作 – NetForce1 2010-02-26 15:29:46