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?

  1. create addin has fields declared in module.

    public testme integer

  2. also declare public function in same addin module field value.

    public function gettestme() integer gettestme = testme end function

  3. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -