change links by a macro

  • Thread starter Thread starter JohnQ
  • Start date Start date
J

JohnQ

I'm using the macro below to change the input file.
I have to do this for 20 spreadsheets which contains 5
similar links each.

The problem is that excel is not been able to locate the
new file and or path.


Sheets.Select

Cells.Select

Selection.Replace What:= _
"H:\2004\[source.XLS]", _
Replacement:= _
"H:\2005\[source.XLS]", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
 
Unless the What string doesn't match entries in the cells, it should work.

Does it work when you do it manually. If so, turn on the macro recorder
while you do it manually and capture the code.
 
JohnQ said:
I'm using the macro below to change the input file.
I have to do this for 20 spreadsheets which contains 5
similar links each.

The problem is that excel is not been able to locate the
new file and or path.


Sheets.Select

Cells.Select

Selection.Replace What:= _
"H:\2004\[source.XLS]", _
Replacement:= _
"H:\2005\[source.XLS]", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

Not sure exactly what you want here, but a simple way to make changes in
multiple files is as follows:
this code looks through all open workbooks, writing "Hello" in the top left
cell of sheet 1

For each w in Workbooks
w.Sheets(1).Cells(1,1).Value = "Hello"
Next


If you nest your replace calls inside that For loop, it will replace on
every open workbook.

Iain King
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top