C
CDMAPoster
In:
http://groups.google.com/group/microsoft.public.access/msg/f16be594f6541bc6
Stefan Hoffmann said:
You can use Jet in a query to export data to a new file:
SELECT *
INTO [Excel 8.0;Database=YourPath/File.xls].[SheetName]
FROM table
I'm writing some VBA code with a reference to 'Microsoft DAO 3.6
Object Library' to import data from the first worksheet of whatever
Excel (2003) file the user selects. In order to get the name of the
first worksheet of the selected file, I also referenced 'Microsoft
ActiveX Data Objects 2.1 Library' and ran the following code, most of
which was from http://support.microsoft.com/kb/257819/EN-US/ under the
section entitled "ODBC Provider Using a DSN-Less Connection String":
'---Begin module code---
Private Function GetExcelFirstWorksheetName(strFileName As String) As
String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.Provider = "MSDASQL"
.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" &
"DBQ=" & strFileName & ";ReadOnly=True;"
.Open
End With
Set rs = cn.OpenSchema(adSchemaTables)
rs.MoveFirst
GetExcelFirstWorksheetName = rs(2)
rs.Close
cn.Close
End Function
'---End module code---
which I then use as part of my DAO SQL string, something like:
strSQL = "SELECT * FROM [" & strWorksheetName & "];"
Set DAOWS = DBEngine.Workspaces(0)
Set DAODB = DAOWS.OpenDatabase(strFileName, False, True, "Excel
8.0;HDR=No;")
Set DAORS = DAODB.OpenRecordset(strSQL, dbOpenForwardOnly)
Do While Not DAORS.BOF And Not DAORS.EOF
....
Loop
BTW, the file browser code I used (with slight modifications) was from
(Hasler Thomas):
http://www.codeproject.com/vbscript/filebrowse.asp
The code is being run in Catia 5 but these newsgroups seem like the
best place to ask.
It all works, but is there a simpler way to get the name of the first
worksheet of the selected Excel file?
James A. Fortune
(e-mail address removed)
(e-mail address removed)
http://groups.google.com/group/microsoft.public.access/msg/f16be594f6541bc6
Stefan Hoffmann said:
You can use Jet in a query to export data to a new file:
SELECT *
INTO [Excel 8.0;Database=YourPath/File.xls].[SheetName]
FROM table
I'm writing some VBA code with a reference to 'Microsoft DAO 3.6
Object Library' to import data from the first worksheet of whatever
Excel (2003) file the user selects. In order to get the name of the
first worksheet of the selected file, I also referenced 'Microsoft
ActiveX Data Objects 2.1 Library' and ran the following code, most of
which was from http://support.microsoft.com/kb/257819/EN-US/ under the
section entitled "ODBC Provider Using a DSN-Less Connection String":
'---Begin module code---
Private Function GetExcelFirstWorksheetName(strFileName As String) As
String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.Provider = "MSDASQL"
.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" &
"DBQ=" & strFileName & ";ReadOnly=True;"
.Open
End With
Set rs = cn.OpenSchema(adSchemaTables)
rs.MoveFirst
GetExcelFirstWorksheetName = rs(2)
rs.Close
cn.Close
End Function
'---End module code---
which I then use as part of my DAO SQL string, something like:
strSQL = "SELECT * FROM [" & strWorksheetName & "];"
Set DAOWS = DBEngine.Workspaces(0)
Set DAODB = DAOWS.OpenDatabase(strFileName, False, True, "Excel
8.0;HDR=No;")
Set DAORS = DAODB.OpenRecordset(strSQL, dbOpenForwardOnly)
Do While Not DAORS.BOF And Not DAORS.EOF
....
Loop
BTW, the file browser code I used (with slight modifications) was from
(Hasler Thomas):
http://www.codeproject.com/vbscript/filebrowse.asp
The code is being run in Catia 5 but these newsgroups seem like the
best place to ask.
It all works, but is there a simpler way to get the name of the first
worksheet of the selected Excel file?
James A. Fortune
(e-mail address removed)
(e-mail address removed)