Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Reference named range in closed workbook

Thanks

It runs well but lists worksheets and named ranges

How can I identify the named ranges only and more important, how can
I copy the named range content to the clipboard?

Avi


If you explore the samples in the download link I gave you, you'll see
how to load the contents of a named range into a recordset. Once there
you can do whatever you want with the data. Assuming you want to put it
into the Clipboard for pasting somewhere, you can bypass that step and
transfer the data directly to wherever...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reference named range in closed workbook

Thanks I'll explore it
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reference named range in closed workbook

Strange behavior with the provided sample sales.xls (or any other wbk)
szSQL = "SELECT * FROM [Sales$A1:E19];"
Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
Sheet1.Range("A1").CopyFromRecordset rsData

If a column contains both numerical and string values, only the numerical values are copied !!!

Any idea?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reference named range in closed workbook


Looks as I found the solution for my own question

I have to use HDR=YES;IMEX=1"; in the connection string

Avi
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Reference named range in closed workbook

Looks as I found the solution for my own question

I have to use HDR=YES;IMEX=1"; in the connection string

Avi


Ok! Glad you were able to figure it out. It does take a bit of practice
to catch on to the nuances related to working with text files and
workbooks, being they both have/use different criteria args in their
respective SQL statements. For this reason I use a wrapper function to
return the data, which accepts 'sSource$' args "mdb", "wkb" or "txt"
which uses a 'Select Case' construct to build the appropriate SQL
statement. Also required as arg is 'sSelect$' which contains the table
info for building the "SELECT FROM" part. I use it like this...

<snip
Set RS = GetRS(sTable, "mdb") 'database file
Set RS = GetRS(sTable, "wkb") 'Excel file
Set RS = GetRS(sTable, "txt") 'text file
</snip

The function also determines whether to use "Jet" or "Ace" depending on
Excel version (though Jet is still working in all). This allows me to
reuse the function for any number of recordsets I want to access during
runtime without having to 'hard code' every time. Once you're familiar
with how ADODB works you may want to build your own reusable function!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reference named range in closed workbook

Thanks again

Now I am facing a new annoying issue: numbers are copied as "number stored as text" format

Is there a straightforward solution?

BTW, where can I find the wrapper function and how is it used in VBA?

Avi
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Reference named range in closed workbook

Thanks again

Now I am facing a new annoying issue: numbers are copied as "number
stored as text" format

Is there a straightforward solution?


You'll need to format the fields (columns) containing numbers/dates as
desired per your data layout on the target sheet.

BTW, where can I find the wrapper function and how is it used in VBA?


This is a 'make-your-own' thingy that you configure for how you (want
to) work with data. I don't have an encapsulated wrapper because I
rarely use ADODB, and when I do I use SQLite.

The same principles apply, though, and so you should be able to do same
for your VBA projects by putting everything ADODB related in a standard
module that you can import into any project as needed. My earlier
example of how to use such a function was a rather simplified sample of
a more complex process which is generic so I can use it with VB6
projects as well as VBA projects. This is stored in a text file from
which I grab snippets on an as needed basis. (I primarily use '.dat'
files for storing data so I can work with the standard VB[A] built-in
I/O functions and arrays)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Reference named range in closed workbook


One more issue,please

In the sample you provide, I use
' Query based on a sheet-level range name.
'szSQL = "SELECT * FROM [EZZ$ddd];"

where EZZ is the sheet name and ddd the sheet-level range name

I get an error stating that the engine can't find the object EZZ$ddd

No chance also with a workbook level name

Thanks again for your very valuable help
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
VBA code to copy named range in closed workbook Phraedrique Excel Programming 2 June 19th 09 08:51 PM
Workbook named range not seen by ADO when workbook closed Tim Lund[_2_] Excel Programming 2 March 16th 07 08:59 AM
ADO - closed workbook - Named range MattShoreson[_16_] Excel Programming 2 August 31st 05 10:37 AM
referencing a named range from a closed workbook Gixxer_J_97[_2_] Excel Programming 4 April 8th 05 08:45 PM


All times are GMT +1. The time now is 05:07 PM.

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

About Us

"It's about Microsoft Excel"