XL2K: How to reference workbooks that aren't open?

  • Thread starter Thread starter Mike Mertes
  • Start date Start date
M

Mike Mertes

I can't seem to find any functions I can use to retrieve data from cells in
workbooks that aren't open.

I'm familiar with links, DDE, OLE, etc. But, I only know how to link with
spreadsheet formulas rather than VBA code.

Can someone point me in the right direction?

TIA!
 
Thanks for your quick response, Ron.

I'm not able to visit your page from work because of Websense: "Reason: The
Websense category "Freeware and Software Download" is filtered." (I guess
the admins at HQ don't want their technology specialists to be able to
download anything useful :P )

So I'll quickly elaborate here:
In actuality, the only reason I wanted to reference data in unopened
workbooks is because I was under the impression that opening each (while
easily codable,) would be very slow. Can I just turn off screen updating to
speed the process?

Also, I'll bookmark the links you gave me for future study. (As I always
do.)

Thanks again. :)
 
Ron..

re the Array_Sort procedure on your ado page ...

far as i can tell it isn't called from any of the other procs..

BUT when you post a sort routine... wouldn't it make more
sense to post a QuickSort rather than this ugly/slow "Shell" sort?

AND when you'd need to sort it would even make more sense
to let SQL do the sorting...

<grin>



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Ron de Bruin wrote :
 
Hi Keepitcool
far as i can tell it isn't called from any of the other procs..
This sub use it
Sub GetData_Example3()

BUT when you post a sort routine... wouldn't it make more
sense to post a QuickSort rather than this ugly/slow "Shell" sort?

AND when you'd need to sort it would even make more sense
to let SQL do the sorting...

It is working and that's important to me.
I learn everyday try to understand the things i see and read.

My Webpage is my Help file<g>
I now more about growing flowers then about SQL
 
Mike Mertes said:
I can't seem to find any functions I can use to retrieve data from cells in
workbooks that aren't open.

Hi Mike:

You can connect with the following ADO Procedure.


Private Sub CommandButton2_Click()

On Error GoTo BadTrip

Dim DB_Name As String
Dim DB_CONNECT_STRING As String

'To use ADO objects in an application add a reference
'to the ADO component. From the VBA window select
'>Tools/References< check the box
' "Microsoft ActiveX Data Objects 2.x Library"

'You should fully quality the path to your file

DB_Name = ("C:\Documents and Settings\") _
& ("The Cat Man\My Documents\Test.xls")

DB_CONNECT_STRING = "Provider=Microsoft.Jet.OLEDB.4.0" _
& ";Data Source=" & DB_Name _
& ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';"

'Create the connection
Dim Cnn As New ADODB.Connection
Set Cnn = New Connection
Cnn.Open DB_CONNECT_STRING

'Test to see if we are connected
If Cnn.State = adStateOpen Then
MsgBox "Welcome to! " & DB_Name, vbInformation, _
"Good Luck TK"
Else
MsgBox "Sorry. No Data today."
End If

'Create the recordset
Dim Rs As ADODB.Recordset
Set Rs = New Recordset

'Determines what records to show
Dim strSQL As String
strSQL = "Select * from [Sheet1$]"

'Retreive the records
Rs.CursorLocation = adUseClient
Rs.Open strSQL, Cnn, adOpenStatic, adLockBatchOptimistic

'Copy the records to the worksheet
Worksheets("Sheet2").Range("A1").CopyFromRecordset Rs

'Close the connection
Cnn.Close
Set Cnn = Nothing

'Destroy the Recordset
Set Rs = Nothing

Exit Sub

BadTrip:
MsgBox "Procedure Failed"
Cnn.Close
Set Cnn = Nothing

End Sub


Good Luck
TK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top