Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Linking to a cell in VBA

I would like to retrieve the value in a named cell in a closed workbook. The
workbook name, sheet name, and range name are known.

Without opening the workbook, is this possible?

Thanks.

JOhn Wirt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Linking to a cell in VBA

John,

here is one way using ADO

Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim sFile As String
Dim oOrig As Worksheet
Dim osh As Worksheet
Dim oCell As Range
Dim aryData

sFile = "C:\myTest\Volker1.xls"

' Create the connection string.
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=Excel 8.0;"

' Query based on the worksheet name.
sSQL = "SELECT * FROM [Sheet1$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

If Not oRS.EOF Then
aryData = oRS.getrows()
Else
MsgBox "No records returned.", vbCritical
End If

MsgBox "Cell A2 contains " & aryData(0, 0)
MsgBox "Cell D4 contains " & aryData(3, 2)

' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I would like to retrieve the value in a named cell in a closed workbook.

The
workbook name, sheet name, and range name are known.

Without opening the workbook, is this possible?

Thanks.

JOhn Wirt




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Linking to a cell in VBA


"Bob Phillips" wrote in message
...
John,

here is one way using ADO

Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim sFile As String
Dim oOrig As Worksheet
Dim osh As Worksheet
Dim oCell As Range
Dim aryData

sFile = "C:\myTest\Volker1.xls"

' Create the connection string.
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=Excel 8.0;"

' Query based on the worksheet name.
sSQL = "SELECT * FROM [Sheet1$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

If Not oRS.EOF Then
aryData = oRS.getrows()
Else
MsgBox "No records returned.", vbCritical
End If

MsgBox "Cell A2 contains " & aryData(0, 0)
MsgBox "Cell D4 contains " & aryData(3, 2)

' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Wirt" wrote in message
...
I would like to retrieve the value in a named cell in a closed workbook.

The
workbook name, sheet name, and range name are known.

Without opening the workbook, is this possible?

Thanks.

JOhn Wirt






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
linking a text formatted cell to a formula cell lacy Excel Discussion (Misc queries) 1 May 22nd 09 03:19 PM
linking to contents of a cell vs cell address AinSF Excel Worksheet Functions 0 September 6th 06 06:57 PM
linking to a cell within a text cell or comment BlueJ2005 Excel Worksheet Functions 0 May 11th 06 10:36 PM
linking a cell with a specific letter value to a cell with a formu tommo64 Excel Worksheet Functions 4 April 3rd 06 10:44 AM
Linking a cell to another workbook cell based on a variable name Brian Excel Discussion (Misc queries) 6 June 1st 05 11:54 PM


All times are GMT +1. The time now is 10:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"