How do I refer to external workbooks in VBA using a unique identifier which doesn't change when the file is open? It works fine when the full filepath is included and no file with the same name is open. However when a file is open the complete form with the filepath does not work and the filename alone does not work.
I wanted to create an update Sub to update all the references and this mucks itself up if the spreadsheet is open (refer to point 2 below).
These are some reasons why I feel it should be possible:
- It seems that in the manual link update menu there is only the filename to refer to;
- Also one can't open two workbooks with the same name, and thus if you open a source link then the cell references change from a file path to a file name (and it is this very thing which is causing an issue.
This is the code I currently has the updCellRef
is a cell reference to the file-path (where I just want to use the file-name):
Sub updateValues(updCellRef)
updFilePath = ActiveWorkbook.Sheets("INPUTS").Range(updCellRef).Value
ActiveWorkbook.updateLink Name:=updFilePath, Type:=xlExcelLinks
End Sub
To clarify this problem arose when I was using the above function to update values however when the source spreadsheet was open it is referenced by its file name alone. When it is closed it is referenced by its full file-path.
I'm using Excel Professional 2010 v14 with VBA v7.0
Note: I don't want to use any other software including Power Query as it can't be installed without admin rights.