Why would VBA TypeOf operator fail in EXCEL -
i have been fighting excel 2007 problem several days now. below listing of facts can think of might relevant:
- idetailsheet class declared in vba project several methods, , throws error in class initializer cannot instantiated (making abstract).
- option explicit set in modules.
- ten worksheets in vba project implement *idetailsheet* , compile cleanly (as entire project).
- cdetailsheets class declared in vba project wraps collection object , exposes collection object collection of idetailsheet. exposes additional methods perform methods of idetailsheet on collection menmbers.
in class initializer (called workbook_ open event handler , assigned global variable), cdetailsheet executes following code populate private collection detailsheets:
dim sht excel.worksheet
each sht in activeworkbook.worksheets
if typeof sht idetailsheet then
dim detailsheet idetailsheet
set detailsheet = sht
detailsheets.add detailsheet, detailsheet.name
end if
next sht
in ribbon call-backs following code run:
if typeof activeworkbook.activesheet idetailsheet then
dim detailsheet idetailsheet
set detailsheet = activeworkbook.activesheet
detailsheet.refresh [correction]
end ifall activex controls have been removed workbook, after having been identified other stability issues (there few dozen originally). fluent interface ribbon has been created replace functionality associated activex controls.
there hyperion add-in corporate template, not used in workbook.
when said , done, following symptom occurs when workbook run:
- any number of instances of idetailsheet recognized in cdetailsheets initializer typeof is, 1 (most common) 2 or 3. never zero, never more 3, , never full 10 available. (not same one, though being near front of set seems increase likelihood of being recognized.)
- whichever instances of idetailsheet implementation discovered in cdetailsheets initializer (and near can determine, such instances) recognized typeof ... is in ribbon call-back.
can explain why of typeof ... is operations failing? or how fix issue?
i have resorted manually creating v-tables (ie big ugly select case ... end select statements) functionality working, find rather embarrassing have name beside such code. besides which, can see being future maintenance nightmare.
update:
thinking might stale p-code issues, went extent of deleting project.bin file expanded xlsm zip, , manually importing vba code in. no change. tried adding project name usages of idetailsheet make them mifab.idetailsheet, again no avail. (mifab project name.)
there few ways cheat using callbyname. you're going have work around bug 1 way or another.
a quick dirty example
every sheet starts implementing line should have public gettype function. attached "testsheet" sub button on ribbon. puts returned type name in cell a1 demonstrate function.
module1
'--- start module1 --- option explicit public sub testsheet() dim obj object set obj = activesheet activesheet.[a1] = gettype(obj) end sub public function gettype(obj object) string dim returnvalue string returnvalue = typename(obj) on error resume next returnvalue = callbyname(obj, "gettype", vbmethod) err.clear on error goto 0 gettype = returnvalue end function '--- end module1 ---
sheet1
'--- start sheet1 --- implements class1 option explicit public function class1_testfunction() end function public function gettype() string gettype = "class1" end function '--- end sheet1 ---
Comments
Post a Comment