Lorenzo Rigamonti
Lorenzo Rigamonti

Reputation: 1775

Using Excel's UpdateLink() method from VBScript

I want to update all the links in a certain Excel file and I put the code on a VBScript. What is wrong with the following code?

file = Directory2 & Filename2
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(file)
objExcel.Application.Visible = True
objExcel.ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources 
objExcel.ActiveWorkbook.Save 
objExcel.ActiveWorkbook.Close

This returns:

Error code: 800A0400

Upvotes: 2

Views: 2020

Answers (1)

Bond
Bond

Reputation: 16321

VBScript doesn't support named parameters (Name:=ActiveWorkbook.LinkSources)

Name is the first argument to UpdateLink(), however, so just pass the value:

objWorkbook.UpdateLink objWorkbook.LinkSources

You were also using ActiveWorkbook without qualifying it. You need to use either:

objExcel.ActiveWorkbook.LinkSources

or

objWorkbook.LinkSources

Upvotes: 4

Related Questions