FozzyBear
FozzyBear

Reputation: 1

Unable to set object VBA

I keep getting

run time error 13, type mismatch.

I have the below code:

Dim wkbObj As Workbook
Other dims

Set wkbObj = GetObject(This Workbook.Path & "Contacts_SF. xlsx")

The above line is where the error occurs and I can't figure out why. Tried different variations to set the wkbObj but get similar errors.

Upvotes: 0

Views: 166

Answers (1)

Alex de Jong
Alex de Jong

Reputation: 1267

I think you get an error because of the spaces and I think you miss a backslash. But you can also use

Set wkbObj = Application.Workbooks.Open(Thisworkbook.Path & "\Contacts_SF.xlsx")

or if it is already open

Set wkbObj = Application.Workbooks("Contacts_SF.xlsx")

Upvotes: 2

Related Questions