Here's a somewhat convoluted approach...but it works!
You need some VBA code to extract the formula as a text string then you can
extract the filename from that text string.
So, let's assume cell A1 contains this formula:
=SUM('C:\TV\[test1.xls]Sheet1'!$A$1:$A$5)
Create this user defined function:
Function GetFormula(cell_ref As Range) As String
Application.Volatile
If cell_ref.HasFormula Then
GetFormula = cell_ref.Formula
Else
GetFormula = ""
End If
End Function
To install this UDF:
In the file that you want to do this:
Open the VBE editor - ALT F11
Open the Project Explorer - CTRL R
Find your filename in the pane that opens
Right click on the filename and select Insert>Module
Copy/paste the above code into the window that opens
Return to Excel - ALT Q
Enter this formula in cell B1:
=LEFT(MID(getformula(A1),FIND("[",getformula(A1))+1,255),FIND("]",MID(getformula(A1),FIND("[",getformula(A1))+1,255))-1)
Based on the sample formula above, the result is: test1.xls
Note: no error checking! Assumes that the referenced cell does in fact
contain a formula with external references. Also, will not work on formulas
with named external references.
--
Biff
Microsoft Excel MVP
"camexcel" <(E-Mail Removed)> wrote in message
news:EFEA6668-4B08-40EA-BCF3-(E-Mail Removed)...
> In the current workbook I have a formula linked to another spreadsheet.
> What
> I want to do in the current workbook is to extract the filename only into
> a
> column to represent the source of the file linked..
>
|