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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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
Bill PrewIT / Software Engineering ConsultantCommented:
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Bill PrewIT / Software Engineering ConsultantCommented:
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.
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.