Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default How To Import Excel Data With Excel 2007?

Hi Everyone

I have a macro in Excel 2003 that imports Excel data from a separate
Excel file. I can't seem to figure out how to do this with Excel
2007. Can you please help?

Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How To Import Excel Data With Excel 2007?

It happens that Andy formulated :
Hi Everyone

I have a macro in Excel 2003 that imports Excel data from a separate
Excel file. I can't seem to figure out how to do this with Excel
2007. Can you please help?

Andy


XL2003 and earlier use a different data provider than XL2007 and later.
The former uses JET; the latter uses ACE. What you need to do is make
your code version aware so that it knows which provider to use based on
the version of Excel that it's running in.

Example:
Construct a connection string something like this:
If Application.Version = 12 Then
'use ACE provider connection string
Else
'use JET provider connection string
End If

This precludes that you'll have to construct 2 separate connection
strings. You could use constants for this:

Const sProvider As String = "Microsoft.Jet.OLEDB.4.0;"
Const sExtProps As String = "Excel 8.0;"

Const sProvider12 As String = "Microsoft.ACE.OLEDB.12.0;"
Const sExtProps12 As String = "Excel 12.0 Xml;"

If you know the data source beforehand, you could configure your code
something like this:

<aircode
' Use a var to hold data source
sDataSource = "<FullPathAndFilename"
If Application.Version = 12 Then
'use ACE provider connection string
sConnect = "Provider=" & sProvider12 & _
"Data Source=" & sDataSource & _
"Extended Properties=" & sExtProps12
Else
'use JET provider connection string
sConnect = "Provider=" & sProvider & _
"Data Source=" & sDataSource & _
"Extended Properties=" & sExtProps
End If
</aircode

' Construct your SQL statement
sSQL = "SELECT * FROM..."

' Grab the data into a recordset
Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly,
adCmdText

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
How do I import data into Excel from Bloomberg using Excel 2007? Graeme Excel Discussion (Misc queries) 2 March 19th 10 07:02 AM
Where is the Data Import Excel button in Excel 2007 Joe L Excel Discussion (Misc queries) 6 March 9th 10 01:00 PM
Import Access data into Excel 2007 rick Excel Discussion (Misc queries) 0 April 28th 09 09:34 PM
Data Import to Excel Issue with Excel 2007 and Excel 2003 on same Melsh Excel Discussion (Misc queries) 0 August 1st 07 09:32 PM
Import sharepoint data to Excel 2007 [email protected] Excel Programming 0 July 6th 07 08:43 PM


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

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"