Excel VBA, Custom Class: Function call raises "method not supported" error -
i writing first classes. 1 ccrelist collection of ccre instances (some specialized events).
i want there sub or function inside ccrelist load cre's worksheet 1 big collection can work with. created function , worked ok when called normal code module, tried move code class. having trouble calling function loadfromworksheet(myws worksheet).
the error "object not support property or method". have tried making sub, function, making public, not public, have tried turning property let instead of sub. have flimsy grasp on does. have tried
call crelist.loadfromworksheet(myws)
and
crelist.loadfromworksheet myws
same error every time.
here test code uses class , calls function:
sub testclassobj() dim crelist ccrelist set crelist = new ccrelist dim myws worksheet set myws = thisworkbook.activesheet crelist.loadfromworksheet (myws) end sub
here snippet of class ccrelist:
' **** class ccrelist option explicit ' collection of cre objects private pcrelist collection private sub class_initialize() set pcrelist = new collection end sub public property cres() collection set cres = pcrelist end property public property set add_cre(acre ccre) pcrelist.add acre end property function loadfromworksheet(myws worksheet) dim cre ccre dim ifirst long dim ilast long dim long set cre = new ccre ifirst = gheader_row + 1 ilast = findnewrow(myws) - 1 ' update data in cre add = ifirst ilast if myws.cells(i, gcre_col) <> "" ' cre row set cre = new ccre cre .cre_id = myws.cells(i, gcre_col) if not isdate(myws.cells(i, gcre_eta_col)) .eta = "1/1/1900" else .eta = trim(myws.cells(i, gcre_eta_col)) end if <... snipped ...> end pcrelist.add_cre cre end if next end sub ' **** end of class ccrelist
thanks expertise.
here worked based on got in comments. first, did "break in class module". in test code, changed function call from:
crelist.loadfromworksheet(myws)
to
crelist.loadfromworksheet myws
inside class, had change
set pcrelist.add_cre cre
to
pcrelist.add cre
then able rid of extraneous class functions add_cre , count.
thanks everyone's input. couldn't figure out how mark comments accepted answers did this. let me know if need differently. works!
Comments
Post a Comment