Excel VBA module static variable comes to Nothing after use -


i trying share variable between 2 subroutines in module.

i have declared variable @ top of file:

option explicit private targetworkbook workbook 

i have 2 subroutines, 1 set it, , 1 use multiple times. setter pretty simple:

sub setwbtarget()     set targetworkbook = thisworkbook end sub 

the using subroutine runs fine first time, calls foul when running subsequently until set again.

here truncated user of static (not global) variable

sub testtargetworkbook()     if (targetworkbook nothing)         msgbox "need set targetworkbookfirst. stopping", vbokonly, _             "failed transfer"     else         dim wb workbook         dim ws worksheet         dim twb workbook          set wb = thisworkbook         set ws = wb.worksheets(1)         set twb = targetworkbook         ws.activate     end if end sub 

edit: did not finish subsequent calls, rather single-stepped until bad happen, reset project. of course cleared shared variable.

i kept entry here because searching did not locate similar answer. if entry marked duplicate, please put link duplicate question/answer


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -