I found a very clumsy workaround that does work, but there has to be a better way.
Dim targetfile
Dim tempbook As Workbook
Dim databook As Workbook
Set databook = Workbooks("Database.xlsm")
targetfile = Application.GetOpenFilename("Excel Files (*.xlsm),*.xlsm")
If Filename <> "False" Then
Set tempbook = Workbooks.Open(targetfile)
End If
databook.Activate
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Database")
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
Worksheets("Calculation").Activate
Range("A1") = targetfile
targetfile = Range("A2")
ws.Activate
Cells(iRow, 1).Select
' Enters the link into the appropriate cell
ActiveCell.FormulaR1C1 = "='[" & targetfile & "]Summary'!R2C3"
Where the cell A2 in calculation has the following formula in place.
=RIGHT(A1,LEN(A1)-FIND("~",SUBSTITUTE(A1,"\","~",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
This returns the part of the string after the last '\'. Which in this instance is the file name. By inputting this into the cell when the referenced workbook is open, it automatically is converted into the full reference when the workbook is closed at the end of the code.
For example, if this string is input into A1. C:\Users\Alkuan\Documents\Example.xlsm
A2 returns, Example.xlsm
As i said, very clumsy and there must be a better way to achieve this.
Bookmarks