Reputation: 303
I have 2 excel files and in main excel file I have 2 comboBox elements, one of them should be populate from another worksheet and 2nd from another workbook and when I'm trying to populate this combobox by using data from another workbook like this
Private Sub Worksheet_Activate()
ThisWorkbook.Sheets("Master").ComboBox23.List = Sheets("Modification").Range("C2:C55").Value
ThisWorkbook.Sheets("Master").ComboBox24.List = GetObject(ThisWorkbook.Path & "\resourcetracker.xls").Sheets("Resources").Range("A2:A22").Value
End Sub
I can get data from another worksheet in main excel file, but line where i'm opening another workbook gives me an error
Invalid procedure call or argument (Run-time Error 5)
Can someone help with to understand what i'm doing wrong? Thanks
Upvotes: 0
Views: 428
Reputation: 11755
GetObject
is not the right way to open another WorkBook
Try this instead
Public Sub Worksheet_Activate()
Dim wb As Workbook
ThisWorkbook.Sheets("Master").ComboBox23.List = Sheets("Modification").Range("C2:C55").Value
Set wb = Workbooks.Add(ThisWorkbook.Path & "\resourcetracker.xls")
ThisWorkbook.Sheets("Master").ComboBox24.List = wb.Sheets("Resources").Range("A2:A22").Value
wb.Close False
End Sub
Upvotes: 0