shrub
Status: New User - Welcome
Joined: 25 Jan 2008
Posts: 1
Back to top
Posted: Jan 25, 08, 9:43    Command line script to search folder and remove Word macros
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")

objDoc.Save()
objDoc.Close()

Next
End Sub

objWord.Quit()
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 848
Location: East Coast, West Coast? I know it's one of them.
Back to top
Posted: Jan 25, 08, 11:08    
We don't offer MS word macro support here, sorry.

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

All times are GMT - 8 Hours