Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Application.Run and pass variables to Sub

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Application.Run and pass variables to Sub

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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Application.Run and pass variables to Sub

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass variables as arguments of a function Excel-craze Excel Worksheet Functions 1 August 12th 09 11:48 AM
Pass variables from Worksheet_Calculate sub to Module John Michl Excel Programming 2 June 22nd 06 04:12 PM
Pass variables value to Shell wpw3 Excel Programming 0 March 7th 05 03:55 PM
can variables pass values Don[_11_] Excel Programming 3 November 1st 03 04:50 PM
Pass Variables into Form's code Stuart[_5_] Excel Programming 3 August 23rd 03 04:55 AM


All times are GMT +1. The time now is 05:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"