PC Review


Reply
Thread Tools Rate Thread

Application.Run and pass variables to Sub

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      26th Sep 2008
Can this be done? How do I do it.

Let's say my sub is in TestWB.XLS, the Sub name is MySub and I need to pass
two variables, aWB, oWB

Application.Run("TestWB.xls!mySub(aWB,oWB)") ???

Can this be done?

Barb Reinhardt

 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      26th Sep 2008
You can't pass objects, which is what I assume aWB and oWB are, but you can
pass numbers and strings as literals or variables. You'd need to recreate
your object based on the name or index passed as an argument.

Sub test()
Dim n As Long, result
n = 3
result = Application.Run("abc", n, 123, ActiveSheet.Name, "hello")
MsgBox result & " " & ActiveSheet.Name
End Sub

Function abc(num1 As Long, num2 As Long, s1 As String, s2) As Long
ActiveWorkbook.Worksheets(s1).Name = s2
abc = num1 * num2
End Function

Above is just a quick test within the same project. To call in another
project apart from qualifying with the workbook name it's worth including
the module

Application.run "mybook.abs!module1.abc"

Regards,
Peter T


"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:8EA68713-B66B-4656-920C-(E-Mail Removed)...
> Can this be done? How do I do it.
>
> Let's say my sub is in TestWB.XLS, the Sub name is MySub and I need to
> pass
> two variables, aWB, oWB
>
> Application.Run("TestWB.xls!mySub(aWB,oWB)") ???
>
> Can this be done?
>
> Barb Reinhardt
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      26th Sep 2008
This worked for me:

Option Explicit
Sub testme01()

Dim OtherWkbk As Workbook

Set OtherWkbk = Workbooks("book2.xls")

Application.Run "'" & OtherWkbk.Name & "'!testme", _
Workbooks("book3.xls"), ThisWorkbook

End Sub

And in the other workbook:

Option Explicit
Sub testme(aWB As Workbook, oWB As Workbook)
MsgBox aWB.FullName & vbLf & oWB.FullName
End Sub





Barb Reinhardt wrote:
>
> Can this be done? How do I do it.
>
> Let's say my sub is in TestWB.XLS, the Sub name is MySub and I need to pass
> two variables, aWB, oWB
>
> Application.Run("TestWB.xls!mySub(aWB,oWB)") ???
>
> Can this be done?
>
> Barb Reinhardt


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass variables between VBScript and VB.net ? Rob Microsoft VB .NET 3 18th Oct 2007 01:55 PM
how to pass variables from asp.net to asp ? jpm Microsoft ADO .NET 1 3rd May 2006 12:51 PM
How to pass variables in the URL? Miguel Dias Moura Microsoft ASP .NET 1 2nd Dec 2004 06:44 PM
I want to pass 2 variables using a dropdown Dave Microsoft Frontpage 3 1st Dec 2004 09:20 PM
Re: Class public shared Variables vs. Application Variables in ASP.NET avnrao Microsoft ASP .NET 0 7th May 2004 06:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.