ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ChangeLink (https://www.excelbanter.com/excel-programming/289131-changelink.html)

Joe Bannister

ChangeLink
 
Hello all,
Can anyone help please?

I have a spreadsheet that rolls forward on a weekly basis.
Much of the data is pulled in from other spreadsheets
which also roll forward on a weekly basis.

The following is the code i use:

secondFilename = "C:\headoffice\"
secondFilename = secondFilename & CStr(Range
("D2").Value)
secondFilename = secondFilename & "_04_abc.xls"

thirdFilename = "C:\headoffice\"
thirdFilename = thirdFilename & CStr(Range
("D2").Value)
thirdFilename = thirdFilename & "_04_def.xls"

Range("X1").Select
Selection.Copy
Range("D2").Select
Selection.pastespecial Paste:=xlPasteValues,
Operation:=xlAdd, SkipBlanks:=False, Transpose:=False

fourthFilename = "C:\headoffice\"
fourthFilename = fourthFilename & CStr(Range
("D2").Value)
fourthFilename = fourthFilename & "_04_abc.xls"

ActiveWorkbook.ChangeLink secondFilename,
fourthFilename, xlLinkTypeExcelLinks

D2 represents the week no.

The sheet can roll forward for weeks without problem and
then i get an error as follows:

Run Time Error
Method 'ChangeLink' of object'_Workbook' failed

and the macro stops on the line:
ActiveWorkbook.Changelink secondFilename, fourthFilename,
xlLinkTypeExcelLinks

Can anyone tell me why this is happening?

Any help much appreciated

Cheers

Joe




All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com