Thomas23 said:
Earl - thank you for taking time to answer my question.
I have another one now, though. I can't seem to get the posted formula
to work - it is exactly what I would like to do. I don't really mind
if the supporting file needs to remain open. I posted a new thread
questioning how to do this.
You mentioned you will use the info to get data from another workbook
(I don't see the new thread), so how about this alternative approach
which uses ADO:
Sub Test()
Dim Con As Object
Dim rs As Object
Dim strCon As String
Dim strSql1 As String
' Amend the following constants to suit
Const PATH As String = "" & _
"C:\data\"
Const FILENAME_XL As String = "" & _
"db.xls"
Const SHEET_XL As String = "" & _
"Sheet1"
' Do NOT amend the following constants
Const CONN_STRING_1 As String = "" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<PATH><FILENAME>;" & _
"Extended Properties='Excel 8.0;HDR=NO'"
' Build connection string
strCon = CONN_STRING_1
strCon = Replace(strCon, _
"<PATH>", PATH)
strCon = Replace(strCon, _
"<FILENAME>", FILENAME_XL)
' Build sql statement
strSql1 = "" & _
"SELECT F1 As Filename" & _
" FROM [" & SHEET_XL & "$A1:A1]"
' Open connection
Set Con = CreateObject("ADODB.Connection")
With Con
.Open strCon
Set rs = .Execute(strSql1)
MsgBox rs!Filename
' Clean up
rs.Close
.Close
End With
End Sub
--