Making a variable available amongst userform routines

  • From Macro1 in WB1 I'm calling Macro2 in WB2. Workbook variable twb (referencing WB1) is passed with the call from WB1. Macro2 loads Userform1, then calls Userform1.getvar(twb) to pass the workbook variable into the Userform. When I enter a change, click or similar event any line referencing twb provides the "object not set" error. I need a way to be able to pass the twb reference after button clicks, change events, etc.


    When I was using a single Macro in a single WB, I set twb as a public variable and it was available in all the Userform subroutines. When I call Macro2 from Macro1, the public variables are not working.


    I'm trying to create a "code engine" that will be utilized by any of 12 different WBs. WB2 is essentially a blank workbook with the necessary code. WB1 contains data customized to that entity, in this case County.

  • Re: Making a variable available amongst userform routines


    Hi Xhunmas,


    Welcome to Ozgrid! Personally I'd approach this at a different angle... Save having Code in 12 separate workbooks I'd look into creating an Add-In


    HTH


    C

  • Re: Making a variable available amongst userform routines


    I'm not familiar with creating add-ins, but I'm intrigued. Can you give me the broad strokes for creating and add-in? For background I program macros and recently downloaded VB 10 Express.

  • Re: Making a variable available amongst userform routines


    Hi Xhunmas,


    You can create an add-in a few ways. One way you'll find on here by doing a search or there is another way by creating an Add-In using VSTO (Visual Studio Tools for Office). There's a good book on it here


    HTH


    C

  • Re: Making a variable available amongst userform routines


    Craig,


    Thanks a lot. After spending a bit of time getting familar with add-ins, I've been able to strip the Macros out of all of the files. My goal is to either place a copy of the add-in on each location or make it available on a central server (preferred).


    I greatly appreciate you help after lurking here for the past 6 months.


    Thanks,
    John

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!