WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Updating Worksheet Links


Question:

I am busy moving hundreds of excel files to a new location. The only problem is the work sheets have links to external excel files. Unfortunately we cannot keep the same directory structure (long story) so the links will be invalid.

Is there a way to programmatically update the links in Excel. Any help would be appreciated.

Answer:

You might be able to accomplish this via OLE. Here is a link to Excels OLE Object Model:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaxl10/html/xlproLinkFormat.asp

You might want to look into 'hyperlink': http://msdn.microsoft.com/library/en-us/vbaxl10/html/xlproHyperlinks.asp?frame=true

Here is some code that seems to work for me:

newpath = "????"
XLS = "C:\temp\linked.xls"
objXL=ObjectOpen("Excel.Application")
objXL.Visible=@TRUE ;Change to @FALSE to hide
objXL.UserControl=@TRUE
objWBK=objXL.Workbooks
objWBK.Open(XLS)
oActWrkbk = objXL.ActiveWorkBook
ForEach objhyperlink In oActWrkbk.Worksheets(1).Hyperlinks
    Message(objhyperlink.Name, objhyperlink.Address))
    objhyperlink.Address = StrCat(newpath,objhyperlink.Address)
Next
oActWrkbk = 0
objWBK = 0
objXL = 0
You will need to modify it to fit your needs.
Article ID:   W17165
File Created: 2007:07:03:14:28:34
Last Updated: 2007:07:03:14:28:34