PC Review


Reply
Thread Tools Rate Thread

ADO - recordset - closed excel workbook - know sheet name and cell name but no named ranges defined

 
 
grahamd
Guest
Posts: n/a
 
      18th Oct 2004
Heres my query

I have a closed work book I wish to extract results from into my open
workbook

1. I know the path where the closed spreadsheet file lives
2. I know the sheet name, sheet name and cell name that i want to read
into my recorset

however NB This sheet is sent to me by someone external and there are
no named ranges in it.

Ive found a code snippet that I thought might suit

Sub GetDataFromClosedWorkbook(ByVal SourceFile As String, _
ByVal SourceRange As String, _
ByVal TargetRange As Range,
ByVal IncludeFieldNames As Boolean)

..
..
..
' it set up the connection to my file

dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" & _
"ReadOnly=1;DBQ=" & SourceFile
Set dbConnection = New ADODB.Connection
dbConnection.Open dbConnectionString

' and calls the execute method to run the query
Set rs = dbConnection.Execute("[" & SourceRange & "]")
..
..
End Sub


The Call works fine provided we use parameters like
Call GetDataFromClosedWorkbook("C:\mySS.xls", "F5:H7",
Range("Target"), False)


But I need to be more specific instead of saying "F5:H7" I need to say
WorkSheets("mySheetName").Range("F5:H7")

ive tried using the .Address() method to return a string
i.e. WorkSheets("mySheetName").Range("F5:H7").Address()

but to no avail

NB: The ADODB method dbConnection.Execute(.....)
expects a string


Any Ideas

Thanks

Graham
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SyBEYWxlcw==?=
Guest
Posts: n/a
 
      18th Oct 2004
Have you tried this:
Call GetDataFromClosedWorkbook("C:\mySS.xls", "'mySheetName'!F5:H7",
Range("Target"), False)

Might work!


"grahamd" wrote:

> Heres my query
>
> I have a closed work book I wish to extract results from into my open
> workbook
>
> 1. I know the path where the closed spreadsheet file lives
> 2. I know the sheet name, sheet name and cell name that i want to read
> into my recorset
>
> however NB This sheet is sent to me by someone external and there are
> no named ranges in it.
>
> Ive found a code snippet that I thought might suit
>
> Sub GetDataFromClosedWorkbook(ByVal SourceFile As String, _
> ByVal SourceRange As String, _
> ByVal TargetRange As Range,
> ByVal IncludeFieldNames As Boolean)
>
> ..
> ..
> ..
> ' it set up the connection to my file
>
> dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" & _
> "ReadOnly=1;DBQ=" & SourceFile
> Set dbConnection = New ADODB.Connection
> dbConnection.Open dbConnectionString
>
> ' and calls the execute method to run the query
> Set rs = dbConnection.Execute("[" & SourceRange & "]")
> ..
> ..
> End Sub
>
>
> The Call works fine provided we use parameters like
> Call GetDataFromClosedWorkbook("C:\mySS.xls", "F5:H7",
> Range("Target"), False)
>
>
> But I need to be more specific instead of saying "F5:H7" I need to say
> WorkSheets("mySheetName").Range("F5:H7")
>
> ive tried using the .Address() method to return a string
> i.e. WorkSheets("mySheetName").Range("F5:H7").Address()
>
> but to no avail
>
> NB: The ADODB method dbConnection.Execute(.....)
> expects a string
>
>
> Any Ideas
>
> Thanks
>
> Graham
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copying sheet to other workbook and named ranges stef Microsoft Excel Discussion 2 27th Jan 2008 09:33 PM
VBA Script to Print several named ranges to PDF with cell-defined filenames jbmessamore Microsoft Excel Programming 0 14th Jul 2006 03:34 PM
supress prompt for named ranges when copying sheet to new workbook neowok Microsoft Excel Programming 1 1st Feb 2006 05:53 PM
INDIRECT and Named Ranges referencing closed workbook gpie Microsoft Excel Worksheet Functions 9 6th Oct 2005 11:24 PM
Access a named cell in a closed workbook Kaak Microsoft Excel Misc 4 25th Mar 2004 01:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:36 AM.