Question posted 2011 ยท +9 upvotes
I get a VBA Excel ‘Compiler Error: Object required’-Error in the marked line. I do not understand the reason.
BTW: Wish Excel would support a .Net language without wrapper needs.
Option Explicit
Public Type Inherit
ReqId As Integer
Parent As Integer
Depth As Integer
Path As String
End Type
Sub test()
Dim MyStructure() As Inherit
ReDim MyStructure(1 To 1000)
MyStructure(1).ReqId = 1
Dim Data, refData As Inherit
Set Data = MyStructure(1) ' <---!
Beep
End Sub
Accepted answer +16 upvotes
Set is for the assignment of objects, a user defined type is treated like a regular variable so use = to assign.
Also (confusingly); Dim Data, refData As Inherit only declares refData of type Inherit to declare them both on one line you must; Dim Data As Inherit, refData As Inherit
Top vba Q&A (6)
- Difference between Visual Basic 6.0 and VBA +122 (2009)
- VBA – how to conditionally skip a for loop iteration +116 (2011)
- VBA: Test if string begins with a string? +53 (2013)
- html parsing of cricinfo scorecards +47 (2012)
- Code to loop through all records in MS Access +46 (2011)
- Access VBA | How to replace parts of a string with another string +44 (2011)
vba solutions on this site
.