Command Line or Batch file approach for Automatically accept all changes, delete all comments and switch off Track Changes in MS Word

VBScript macros based approach has been discussed previously. It worked perfectly fine by changing one line to work with .docx (office365).
I need help to run the VBScript from command line on windows machine. cscript of wscript are throwing error for declaration for FileSystemObject, String, Revision...

Please share steps to rewrite or adapt the previous solution to be able to run from command line on windows machine.
Lak PutchaAsked:
Who is Participating?
Lak PutchaAuthor Commented:

I have used the inputs from
and created another vbscript and called the macro in example.doc file provided in expert-exchange link

Enclosed below the solution i have created for the same.
Thank you for your support, this ticket can be marked as Solved now.

call RunMacro()

Private Sub RunMacro()
    Dim fso
    Dim objFolder 
    Dim objFile 
    Dim strName 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFolder = fso.GetFolder("C:\test")'Or the folder you need searched
	Set objWord = CreateObject("Word.Application")
	objWord.Visible = False
	Set WordDoc ="C:\test\example.doc")
	'Run the macro
	objWord.Run "RunCode_Click" 
 	'Close Word
	'Release the object variables
	Set WordDoc = Nothing 
	Set objWord = Nothing 
End Sub

Open in new window

Bill PrewCommented:
You mention a "previous solution", can you share what that is - either a link to a prior question, or the actual code.  We can't really make suggestions on how to "rewrite or adapt" it unless we know what it is.

Lak PutchaCommented:
Hi I was referring to previous thread in experts-exchange titled
 Automatically accept all changes, delete all comments and switch off Track Changes in MS Word
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Bill PrewCommented:
When you run this as a VBS fom a command line, how do you want to specify the file(s) it should work on?  
  • Will it be a single file, or multiple?
  • Do you want to pas a single file or folder name in on the command line?
  • Or just hard code the file or folder name in the VBS?
  • Some other approach?

Lak PutchaCommented:
Hello Bill,
Hardcode the folder option is fine.
Folder is expected to have multiple files.
Objective is to accept all the changes in each word document in that folder.

PS: The previous soln has a macro button inside a word doc. If the macro can be run from command line then the previous soln meets all our objectives.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.