Word - VBS to launch macro

Hi,

I have a problem on Word and macros.

I use this macro :
Sub refresh()

    Selection.WholeStory
    Selection.Fields.Update
    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"

WordDoc.SaveAs2(oArgs(2))

WordDoc.Close(wdDoNotSaveChanges)

Word.Quit

WScript.Quit

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?

Thanks
CLR BenjaminAsked:
Who is Participating?
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:
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.


»bp
CLR BenjaminAuthor Commented:
Found the solution by my self.

Word 2016 was installed.

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

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.