If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#21
|
|||
|
|||
calculate a formula instead of returning text
O.K. Here's code which will extract data from a specified cell in a closed file. Many thanks to Randy Harmelink: Private Function GetXLSData(sFile As String, sSheet As String, sCell As String) Set oDB = CreateObject("ADODB.Recordset") sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & sFile & ";" & _ "Extended Properties='Excel 8.0;HDR=No'" sSQL = "SELECT * From [" & sSheet & "$" & sCell & ":" & sCell & "]" oDB.Open sSQL, sConn, 3, 3, 1 GetXLSData = oDB.Fields.Item(0).Value oDB.Close Set oDB = Nothing End Function Then, his formula is: =GetXLSData("Lists.xls", "Sheet1","B2") Refer: http://www.excelforum.com/showthread.php?t=531126 http://tinyurl.com/jvrwv -- John James ------------------------------------------------------------------------ John James's Profile: http://www.excelforum.com/member.php...o&userid=32690 View this thread: http://www.excelforum.com/showthread...hreadid=527258 |
#22
|
|||
|
|||
calculate a formula instead of returning text
John James wrote...
O.K. Here's code which will extract data from a specified cell in a closed file. Many thanks to Randy Harmelink: Private Function GetXLSData(sFile As String, sSheet As String, _ sCell As String) Set oDB = CreateObject("ADODB.Recordset") sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & sFile & ";" & _ "Extended Properties='Excel 8.0;HDR=No'" sSQL = "SELECT * From [" & sSheet & "$" & sCell & ":" & sCell & "]" oDB.Open sSQL, sConn, 3, 3, 1 GetXLSData = oDB.Fields.Item(0).Value oDB.Close Set oDB = Nothing End Function Then, his formula is: =GetXLSData("Lists.xls", "Sheet1","B2") .... Several caveats. Most significant, the ADO DLL must be installed. Not sure if this it's installed by default by (or even included with) Standard versions of Office or standalone Excel. Second, this works for single cell sCell, but not for multiple cell ranges, so limited functionality. Other alternatives are given in the following article in the archives. http://groups.google.com/group/micro...443753560f0075 (or http://makeashorterlink.com/?B34B15DCC ). |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need Feedback on table setup | Little Penny | Database Design | 1 | December 28th, 2005 11:32 AM |
Is Access even the right idea? | BMB | New Users | 19 | November 21st, 2005 08:01 PM |
Creating dynamic cross reference links in a Word document | torajudo | General Discussion | 4 | October 25th, 2005 03:51 PM |
Query for 'confirmation' | rogge | Running & Setting Up Queries | 8 | April 19th, 2005 03:26 PM |
Access reports with a horizontal line after each record??? | Bill via AccessMonster.com | Setting Up & Running Reports | 6 | March 9th, 2005 04:51 PM |