Updating Excel Links with VBA

mmaksimovik

New Member
Joined
Sep 26, 2017
Messages
1
Hello guys,

I am new to this forum. Thanks to everyone who is making a contribution, and sharing their knowledge.

I have a whole network of Excel files linked between themselves. At the beginning of every month, I am making copies of each file, reflecting the month and year in the name of each file.
In order not to link them one by one every month, I made a Macro following a simple logic. The Macro seems to work for most of the files, however, in one file, I encountered a problem.

Here is my code:

Dim MISWB As Workbook
Workbooks.Open Filename:="Y:\AM\20" & Godina & "\MIS_" & Godina & "\1MIS" & Godina & Mesec & ".xlsx", UpdateLinks:=0
Set MISWB = ActiveWorkbook

'*****INPUT*****
ChDir "Y:\AM\20" & Godina & "\INPUT_" & Godina
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\INPUT_" & Godina & "\INPUT" & Godina & PrethodenMesec & ".xlsx", NewName:= _
"INPUT" & Godina & Mesec & ".xlsx", Type:=xlExcelLinks

Where:
- Godina = year
- Mesec = current month
- Prethoden mesec = previous month

Well, when I have the file INPUT1709.xlsx open in the background, the Macro seems to be updating the link correctly.
When I don't have it open, and run the Macro, it doesn't change the link correctly, as if "INPUT1709.xlsx" doesn't exist. That's what it says when I click "OPEN SOURCE" from the "EDIT LINKS" tab.

In other files, the same code works without a problem, no matter if the INPUT file is open or not. For example:

'|***********************KWH***********************|
Dim KWHWB As Workbook
Workbooks.Open Filename:="Y:\AM\20" & Godina & "\KWH_" & Godina & "\KWh_" & Godina & Mesec & ".xls", UpdateLinks:=0
Set KWHWB = ActiveWorkbook


'*****INPUT*****
ChDir "Y:\AM\20" & Godina & "\INPUT_" & Godina
ActiveWorkbook.ChangeLink Name:="Y:\AM\20" & Godina & "\INPUT_" & Godina & "\INPUT" & Godina & PrethodenMesec & ".xlsx", NewName:= _
"INPUT" & Godina & Mesec & ".xlsx", Type:=xlExcelLinks

Any ideas what is going on here?

Thank you.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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