R
Rico
Hello,
I have a function in Access that I'm using to open a DAO recordset based on
an Excel spreadsheet. My problem is, when I use the Select statement to get
the informaiton, I have to know what the worksheet name is. I have a couple
of questions here;
1. Is there any way to find out what the worksheet name is or any way to
reference the first worksheet without knowing it's name?
2. If I have to use an Excel object to open the spreadsheet first, is there
any library I can distribute to ensure that this will work on a machine that
does not contain excel?
Here is the code I'm working with...
Public Function OpenExcelDAO(ByVal strPath As String) As DAO.Recordset
On Error GoTo Catch
Dim dbtmp As DAO.Database
Dim tblObj As DAO.TableDef
Dim rs As DAO.Recordset
'If there is nothing to import, then exit
If Not FileExists(strPath) Then GoTo Finally
Set dbtmp = OpenDatabase(strPath, False, True, "Excel 8.0;")
Set rs = dbtmp.OpenRecordset("select * from `owssvr(1)$`")
Set OpenExcelDAO = rs
Set rs = Nothing
Set dbtmp = Nothing
Finally:
Exit Function
Catch:
LogError Err.Number, Err.Description, mstrModule, "OpenExcelDAO"
Resume Finally
End Function
Any help would be greatly appreciated.
Thanks!
Rick
I have a function in Access that I'm using to open a DAO recordset based on
an Excel spreadsheet. My problem is, when I use the Select statement to get
the informaiton, I have to know what the worksheet name is. I have a couple
of questions here;
1. Is there any way to find out what the worksheet name is or any way to
reference the first worksheet without knowing it's name?
2. If I have to use an Excel object to open the spreadsheet first, is there
any library I can distribute to ensure that this will work on a machine that
does not contain excel?
Here is the code I'm working with...
Public Function OpenExcelDAO(ByVal strPath As String) As DAO.Recordset
On Error GoTo Catch
Dim dbtmp As DAO.Database
Dim tblObj As DAO.TableDef
Dim rs As DAO.Recordset
'If there is nothing to import, then exit
If Not FileExists(strPath) Then GoTo Finally
Set dbtmp = OpenDatabase(strPath, False, True, "Excel 8.0;")
Set rs = dbtmp.OpenRecordset("select * from `owssvr(1)$`")
Set OpenExcelDAO = rs
Set rs = Nothing
Set dbtmp = Nothing
Finally:
Exit Function
Catch:
LogError Err.Number, Err.Description, mstrModule, "OpenExcelDAO"
Resume Finally
End Function
Any help would be greatly appreciated.
Thanks!
Rick