Word - VBS to launch macro

CLR Benjamin
CLR Benjamin used Ask the Experts™

I have a problem on Word and macros.

I use this macro :
Sub refresh()

    ActiveWindow.View.ShowFieldCodes = True
    ActiveWindow.View.ShowFieldCodes = False
End Sub

Open in new window

I want to run this macro with this .vbs:

Dim Word

Dim WordDoc

Set oArgs = WScript.Arguments

Set Word = CreateObject("Word.Application")

Word.Visible = False
Set WordDoc = Word.Documents.Open(oArgs(0))

Word.Run "refresh"





Open in new window

here the command I launch to execute this vbs :

cscript C:\refresh.vbs C:\Users\admin\Desktop\a.docx refresh C:\Users\admin\Desktop\b.docx

And nothing happen... here

C:\refresh.vbs(14, 1) Microsoft Word: command failed

Do you have a solution?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Where does the Refresh() macro exist, in a template?

If you comment out this line in the VBS does it still error?

Word.Run "refresh"

Do you have write permission to the folder involved?

You might try running it with:

Word.Visible = True

to see if you get any additional info on screen.

Found the solution by my self.

Word 2016 was installed.

I uninstalled word and installed office 2016 Standard edition, and now it works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial