Command line script to search folder and remove Word macros
Status: New User - Welcome
Joined: 25 Jan 2008
Posts: 1
Reply Quote
I have 2700 Word documents in which the AutoOpen macro fails. I do not want to have to open each document by hand and manually delete the AutoOpen macro.

So, I need to create a script that can be run from the command line to open Word documents from a folder and delete the AutoOpen macro from each document.

I have the code below so far, but one problem is opening the document fires the AutoOpen. Can this be prevented? I've seen the switch /m to stop the macros from running on open, but it doesn't work in the script on the .Open statement.

The second problem is: Are there functions that can be used in the script to delete the AutoOpen macro?

Thanks for any help you can offer.
Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Set FSO = CreateObject("Scripting.FileSystemObject")
DoDir FSO.GetFolder(".")

Sub DoDir(Folder)
On Error Resume Next
Dim File
For Each File In Folder.Files
Set objDoc = objWord.Documents.Open(File.Path /m)

rem objDoc.DeleteMacro("AutoOpen")


End Sub

Back to top
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4126
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
We don't offer MS word macro support here, sorry.

If someone comes along with an answer though, that's of course fine.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours