Hi
I am trying to populate some cells of a worksheet with the names and specific cell values (e.g. cell(1,1) of each worksheet) of a closed workbook without first opening it. The motivation for not opening it is to reduce processing time.
I have found code that partially meets the challenge - it can extract the name of all worksheets (visible and invisible). It follows below.
Any help would be much appreciated.
i_excel
Apologies if this is posted in the wrong place - I am so new to this that I don't know what I'm dealing with.
I am trying to populate some cells of a worksheet with the names and specific cell values (e.g. cell(1,1) of each worksheet) of a closed workbook without first opening it. The motivation for not opening it is to reduce processing time.
I have found code that partially meets the challenge - it can extract the name of all worksheets (visible and invisible). It follows below.
Any help would be much appreciated.
i_excel
Code:
Sub test11()
Dim objConn As ADODB.Connection
Dim objCat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim sConnString As String
Dim sSheet As String
Dim Col As New Collection
Set objConn = New ADODB.Connection
objConn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=test.xlsx; Extended Properties=Excel 12.0;"
Set objCat = New ADOX.Catalog
Set objCat.ActiveConnection = objConn
For Each tbl In objCat.Tables
'If tbl.Visible = True Then
sSheet = tbl.Name
sSheet = Application.Substitute(sSheet, "'", "")
sSheet = Left(sSheet, InStr(1, sSheet, "$", 1) - 1)
On Error Resume Next
Col.Add sSheet, sSheet
On Error GoTo 0
'End If
Next tbl
objConn.Close
Set objCat = Nothing
Set objConn = Nothing
For i = 1 To Col.Count
Cells(24 + i, 2).Value = Col(i)
Next i
End Sub
Apologies if this is posted in the wrong place - I am so new to this that I don't know what I'm dealing with.
Last edited: