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() Back to top |
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 |
All times are GMT - 8 Hours |