Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing the value of variables between projects. 1

Status
Not open for further replies.

GVF

Programmer
Feb 25, 2005
160
US
I have an add-in project open and values have been assigned to variables.

Is it possible to open another add-in project and have it request and receive the values of specific variables from the first project?

The values of the variables will not be changed by project2.

Thanks
 
Are both add-ins open at the same time?

If so...

dimension your variables in a non private module as public

I.E.

public x as integer
public my_text as string
etc...
 
ETID,
Yes, both add-ins are open at the same time.

Whether I Dim the variables as Public or as Global, when I refer to the variable in the second add-in it always comes up as Empty.

Project 1 addin
Public TeamMembers as Integer

Sub Test1()
TeamMembers = 6
End Sub

Project 2 addin

Sub GetValueofTeamMembers()
NewTeam = TeamMembers
End Sub

The above code ends up with NewTeam = Empty

Greg
 
You can store them in a sheet of the first Addin (hidden anyhow...).
Firstly you will define the variables:
Code:
Dim FirstVar as Integer
FirstVar = Workbooks(FirstAddin).Sheets("Store").Range("A2")

Of course you have to take care to memorize them previously...

Fane Duru
 
You can add reference to other vba project, this requires unique name of referenced vba project:

' code in workbook with projCustom named project:
Public TestValue As Integer

Sub SetTestValue()
TestValue = 1
End Sub

' code in workbook with reference to projCustom:
Sub GetTestValue()
MsgBox projCustom.TestValue
' or just
MsgBox TestValue
End Sub

The disadvantage is that the referenced file opens automatically with the file and can't be closed as long as the referencing file is open. The same is for add-ins. Anyway, you can set references programmatically.

You can consider other ways to transfer variables, as application hidden names area ( or registry.

combo
 
Thanks Combo,

I wanted to leave it up to the user to decide if he/she needed the functions contained in Project 2 consequently I did not want Project 2 to open and load its own menu commands just because Project 1 was opened. My remedy was to scrap Project 2 and put all the code in Project 1 and allow the user to load any additional menus from commands contained in my Utilities menu.
I checked out the site that you referenced. It was exactly what I was looking for. Intersesting that the Excel 4.0 macro language continues to refuse to die.

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top