excel - Reference add in global variables from worksheet code -
i'm building excel addin, declares public variables in sub. when addin first used, copies worksheets addin (thisworkbook) user's workbook (activeworkbook). worksheets have worksheet event subs in them.
question: activeworkbook worksheet event subs need reference public variables defined in thisworkboook, can't seem find them. suppose because they're in different workbook. in add-in situation, surely there must way of doing that?
specific example: globaladdin.xlam in module module1 declares
option explicit public testme integer
and then
public sub runsub() testme = 10 msgbox "the addin says testme " & testme end sub
and runsub called thisworkbook._open() event.
globaladdin.xlam made active addin. in workbook book2.xlm in sheet1 hasve
option explicit private sub worksheet_selectionchange(byval target range) msgbox "the worksheet says testme " & testme end sub
now open book2.xlm. dialog box reports value of 10 testme (this xlam workbook_open calling runsub.) clicking on sheet1 in book2 causes variable not defined error, saying testme not defined.
so makes sense, how can access value of testme inside worksheet event in book2?
(edit: suppose pass variables via (hidden) sheet in activeworkbook, seems kind of clumsy. there better way?)
can not following?
create addin has fields declared in module.
public testme integer
also declare public function in same addin module field value.
public function gettestme() integer gettestme = testme end function
now in other workbook in same excel application, late bound call value.
public sub testaddincall() dim x integer x = application.run("gettestme") end sub
this late bound, simplest way.
Comments
Post a Comment