This code can add a defined name to another workbook perfectly fine:
Sub AddDefinedName()
Dim sPath As String
Dim sFilename As String
Dim sSheetname As String
Dim sRangeAddress As String
sPath = "C:\Me\Folder"
sFilename = "source.xls"
sSheetname = "Sheet1"
sRangeAddress = "$A$1:$B$5"
ThisWorkbook.Names.Add "Source", _
RefersTo:="='" & sPath & "\[" & sFilename & "]" & sSheetname & "'!" & sRangeAddress
End Sub
And this code allows to get all the information IF the said workbook is open:
Sub GetDefinedName()
Dim sPath As String
Dim sFilename As String
Dim sSheetname As String
Dim sRangeAddress As String
sPath = Range("Source").Parent.Parent.Path
sFilename = Range("Source").Parent.Parent.Name
sSheetname = Range("Source").Parent.Name
sRangeAddress = Range("Source").Address
MsgBox sPath
MsgBox sFilename
MsgBox sSheetname
MsgBox sRangeAddress
End Sub
How can I get these when the workbook "source.xls" is closed (so I can open it through VBA).