Pass variables between workbooks

bianca.pira

New Member
Joined
Jul 20, 2010
Messages
6
Hi!
Please help me on this issue.
I have 2 workbooks
' B1 workbook

Public Sub UniqueName(params)

MsgBox params(1)
MsgBox params(2)
params(3) = "OK"

End Sub

' B2 workbook
Sub CallAnotherSubroutine()
' Array required to pass parameters
Dim params(1 To 3) As String

params(1) = "Ahhhh"
params(2) = "daaaa"
params(3) = "wrong"

Application.Run "B1.xls!Module1.UniqueName", params

MsgBox params(3)
End Sub

The last MsgBox params(3) returns value "wrong", but i would like it to return the value "OK", which is assigned in Sub UniqueName.
What changes do i have to do in order to obtain the value given in the other procedure?

Thank you.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
First change the project name of the B2 workbook from VBAProject to eg Project1. Then set a reference to that project in the B1 workbook (Tools|References). Then try:

Code:
' B1 workbook
 
Public Sub UniqueName(params)
    MsgBox params(1)
    MsgBox params(2)
    Project1.params(3) = "OK"
End Sub
 
' B2 workbook
 
' Array required to pass parameters
Public params(1 To 3) As String
 
Sub CallAnotherSubroutine()
    params(1) = "Ahhhh"
    params(2) = "daaaa"
    params(3) = "wrong"
    Application.Run "B1.xls!Module1.UniqueName", params
    MsgBox params(3)
End Sub
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I tested the code before I posted it and the MsgBox returned OK. If you have followed my instructions and used the exact code, I don't know why it isn't working for you.
 

bianca.pira

New Member
Joined
Jul 20, 2010
Messages
6
I am using Microsoft Office 2003...

The references for VBAProject (B1.xls) that are marked are:

- Visual Basic For Applications
- Microsoft Excel 11.0 Object Library
- OLE Automation
- Microsoft Office 11.0 Object Library
- Project1

And the new code is
Public Sub UniqueName(params)

MsgBox params(1)
MsgBox params(2)
Project1.params(3) = "OK"

End Sub

Is it possible that more references are required? Or the public declaration of the variable?
 

bianca.pira

New Member
Joined
Jul 20, 2010
Messages
6
Thank u very much.
It worked!!!
I had params declared both as public and in the procedure...
Thank u.
 

Forum statistics

Threads
1,082,323
Messages
5,364,579
Members
400,809
Latest member
formulasataglance

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top