kolcinx
kolcinx

Reputation: 2233

Adding Sheet object to Collection causes RTE 438-Object doesnt support this method

I'm trying to add a Sheet object to a blank Collection.

Line: SheetsCollection.Add (wbTested.Sheets(1))

I want to use this collection of sheets to print their details later in another function.

The code looks like this:

Private Sub TestPrintWorksheetsNames()

    Dim wbTested As Workbook
    Dim SheetsCollection As New Collection

    Set wbTested = Workbooks.Open(ThisWorkbook.Path & "/AddinFunctionsKollarBTestWB.xlsx")
    SheetsCollection.Add (wbTested.Sheets(1))

    With wbTested
        Debug.Print .Name
        Call PrintWorksheetsNames(SheetsCollection)
    End With 'wbTested

    wbTested.Close savechanges:=False
    Set wbTested = Nothing
End Sub

The highlighted line throws an runtime error 438 Object doesnt support this property or method.
Can you please help me with this? Is it possible to add Object types to Collection Object? How?

Upvotes: 0

Views: 91

Answers (1)

user3598756
user3598756

Reputation: 29421

remove brackets

SheetsCollection.Add wbTested.Sheets(1)

Upvotes: 2

Related Questions