CreganTur
05-13-2008, 07:14 AM
I use the following code, in Access, to get the name of the first worksheet in an Excel workbook. This code, in its current state, will only pull the first worksheet name:
Note: strFilepath is the file path of the chosen workbook- it is fed to this code via a choose file dialog box.
'Capture Worksheet name of selected Excel file
'This code only pulls the name of the first worksheet name
Dim bIsWorksheet As Boolean
Dim objConnection As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim lIndex As Long
Dim szConnect As String
'Establish parameters for connection with selected data source
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strFilepath & ";Extended Properties=Excel 8.0;"
Set objConnection = New ADODB.Connection
objConnection.Open szConnect '<<<Create data connection with selected Excel file
'Get list (recordset) of all worksheet names
Set rsData = objConnection.OpenSchema(adSchemaTables)
strSheetName = rsData.Fields("TABLE_NAME").Value '<<<captures name of 1st worksheet
Can anyone help me figure out how to adapt this code so that it will loop through all of the worksheets in the selected workbook?
Note: strFilepath is the file path of the chosen workbook- it is fed to this code via a choose file dialog box.
'Capture Worksheet name of selected Excel file
'This code only pulls the name of the first worksheet name
Dim bIsWorksheet As Boolean
Dim objConnection As ADODB.Connection
Dim rsData As ADODB.Recordset
Dim lIndex As Long
Dim szConnect As String
'Establish parameters for connection with selected data source
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strFilepath & ";Extended Properties=Excel 8.0;"
Set objConnection = New ADODB.Connection
objConnection.Open szConnect '<<<Create data connection with selected Excel file
'Get list (recordset) of all worksheet names
Set rsData = objConnection.OpenSchema(adSchemaTables)
strSheetName = rsData.Fields("TABLE_NAME").Value '<<<captures name of 1st worksheet
Can anyone help me figure out how to adapt this code so that it will loop through all of the worksheets in the selected workbook?