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.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top