excel - VBA Sub or function not defined error in while calling public/private sub in a Class -
i have vba script below:
sub button_click () ' ' < code > ' call findstrings (strfolder, nothing) end sub public sub findstrings(strfolder string, optional wkssheet worksheet = nothing) ' ' < code> ' call processfolder(strfolder, strindent, varstrings, varmatchesfound, varfilenames, lngfoldercount, lngfilecount) end sub private sub processfolder(strfolder string, byref strindent string, byref varstrings variant, byref varmatchesfound variant, byref varfilenames variant, byref lngfoldercount long, lngfilecount long) ' ' < code> ' call processfile(objfile.path, strindent, varstrings, varmatchesfound, varfilenames) end sub private sub processfile(strfullpath string, byref strindent string, byref varstrings variant, byref varmatchesfound variant, byref varfilenames variant) ' ' < code> ' end sub
currently, button_click
, findstrings
in module
, processfolder
, processfile
in class
.
when run button_click
sub-routine, throws error:
sub or function not defined
the error occurs in on call processfolder...
line in findstrings.
i have searched many issues relating error sub or function not defined , tried implement changes answers suggest rectify error, not working.
any regarding error , how rectify appreciated.
if calling methods within class
within module
need instantiate class new
keyword. refer class
methods dot notation.
a general example be:
'module public sub foo() dim o class1 set o = new class1 o.bar end sub 'class1 public sub bar() msgbox "hello world" end sub
which means example do:
'module sub button_click () '< code > call findstrings (strfolder, nothing) end sub public sub findstrings(strfolder string, optional wkssheet worksheet = nothing) ' < code> dim o yourclass set o = new yourclass o.processfolder(strfolder, strindent, varstrings, varmatchesfound, varfilenames, lngfoldercount, lngfilecount) end sub 'yourclass public sub processfolder(strfolder string, byref strindent string, byref varstrings variant, byref varmatchesfound variant, byref varfilenames variant, byref lngfoldercount long, lngfilecount long) ' < code> call processfile(objfile.path, strindent, varstrings, varmatchesfound, varfilenames) end sub private sub processfile(strfullpath string, byref strindent string, byref varstrings variant, byref varmatchesfound variant, byref varfilenames variant) ' < code> end sub
note that:
- in
findstrings
need create new instance ofyourclass
- in
yourclass
processfolder
sub-routine needspublic
Comments
Post a Comment