Hi all, I've been struggling with editing the links contained in the cells of my excel sheet using VBA code. I currently have a large sheet with numerous cells, all containing links for data in another excel file. The sheet has been copied from a version from previous months, and as such I need to find and replace the months(and the year if needed) of every link so that it is the month before(i.e if it is currently April, the month in the links should be changed to March).
This is the code I'm currently using:
However when I try to run this code, it gives me a 'Run-time error '1004 Method ChangeLink of object '_Workbook failed'
Can anyone help with what's wrong with my link to cause this error to show up?
This is the code I'm currently using:
VBA Code:
Sub test4()
Dim a, b, x, y, z As Variant
With ActiveSheet
.Unprotect Password:="" '<-- if any
y = Date - Day(Date)
z = DateSerial(Year(Date), Month(Date) - 1, 0)
x = DateSerial(Year(Date), Month(Date) - 2, 0)
ThisWorkbook.ChangeLink "C:\Users\username\ABC International\(ABCD-FIN)-OJV-efile - Classification " & _
"Type\Country\B1 group\Monthly financials reporting\" & Format$(x, "yyyy") & "\" & Format$(x, "yyyymm") & "\From Terminal\" & _
"Monthly Report - " & Format$(x, "yyyy") & "(3rd Day)_group_" & Format$(y, "mmm") & ".xlsx", _
"C:\Users\username\ABC International\(ABCD-FIN)-OJV-efile - Classification " & _
"Type\Country\B1 group\Monthly financials reporting\" & Format$(z, "yyyy") & "\" & Format$(z, "yyyymm") & "\From Terminal\" & _
"Monthly Report - " & Format$(z, "yyyy") & "(3rd Day)_group_" & Format$(y, "mmm") & ".xlsx"
End With
End Sub
However when I try to run this code, it gives me a 'Run-time error '1004 Method ChangeLink of object '_Workbook failed'
Can anyone help with what's wrong with my link to cause this error to show up?