Please help - 'ChangeLink' of object '_Workbook' failed

LY

New Member
Joined
Apr 14, 2006
Messages
2
Hello everyone,

I'm new here so please have a little patience. Can anyone tell me what
is wrong with the following? I basically have a series of links that
look like these:

S:\Finance\Periodic Reporting\Monthly Files \2006\b_February\AData_2006.xls
S:\Finance\Periodic Reporting\Monthly Files
\2006\b_February\BData_2006.xls -> etc until E

These files are the links in a master files. Every month, these links
have to be updated and only the part that represents a month
(b_february etc) needs to change for the new month. The following
attempts to do just that :
- create a list of new links
- replace old links with these links.
The problem is that the macro works only for the first two links, so
the master file will get updated for Plant(1) and Plant(2). After
Plant(2), I get "'ChangeLink' of object '_Workbook' failed".

Can anyone help me?

Thank you so much,

Puzzled and frustrated


Sub MacroLinks()
Dim MyLinks, OldData, NewData, FixedMonthlyPart
Dim Plant(1 To 5) As String
Dim i As Integer, j As Integer
Dim CurrentMonth As String, NewMonth As String

Plant(1) = "A"
Plant(2) = "B"
Plant(3) = "C"
Plant(4) = "D"
Plant(5) = "E"

FixedMonthlyPart = "S:\Finance\Periodic Reporting\Monthly Files\" &
Year(Date) & "\"

NewMonth = Choose(Month(Date) - 1, "a_January", "b_February",
"c_March", "d_April", "e_May", "f_June", "g_July", "h_August", "i_Sep", "j_Oct", "k_Nov", "l_Dec")

CurrentMonth = Choose(Month(Date) - 2, "a_January", "b_February",
"c_March", "d_April", "e_May", "f_June", "g_July", "h_August", "i_Sep", "j_Oct", "k_Nov", "l_Dec")

MyLinks = ActiveWorkbook.LinkSources(xlExcelLinks)

For i = 1 To UBound(Plant)
NewData = FixedMonthlyPart & NewMonth & "\" & Plant(i) & "Data_" &
Year(Date) & ".xls"
OldData = FixedMonthlyPart & CurrentMonth & "\" & Plant(i) & "Data_" &
Year(Date) & ".xls"
For j = 1 To UBound(MyLinks)
ActiveWorkbook.ChangeLink MyLinks(j), Replace(MyLinks(j), OldData,
NewData)
Next j
Next i

Exit Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You are looping around the links within the loop around the plants - OldData won't be found in all of them.

Can't you just loop around the links replacing CurrentMonth with NewMonth? There's no need to know the plant.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top