Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Application.run and ByRef arguments

Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
.....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Application.run and ByRef arguments

Try dropping the ()'s in your application.run line and add a couple of "'s.

Application.Run "'Book1.xls'!Macro1", A, B



AsIs wrote:

Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Application.run and ByRef arguments

Same effect. :(
--
Чтобы знать: < http://forums.avalon.ru/forum/


"Dave Peterson" пишет:

Try dropping the ()'s in your application.run line and add a couple of "'s.

Application.Run "'Book1.xls'!Macro1", A, B



AsIs wrote:

Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Application.run and ByRef arguments

Sorry, I looked at your post and saw the syntax errors and thought that was your
problem.

Can you rename the project in Book1.xls (away from the default name VBAProject),
then in the second workbook, you can add a reference to that project
(tools|references).

Then this worked ok for me:

Inside Book1.xls:

Option Explicit
Public Function myFunction(x As Long, y As Long) As Boolean

x = x * 2
y = y * 2
myFunction = True

End Function

Inside OtherBook.xls:

Option Explicit
Sub testme2()
Dim a As Long
Dim b As Long
Dim c As Boolean

a = 2
b = 4
c = myFunction(a, b)

Debug.Print a & "-" & b
End Sub

I got:
4-8
in the immediate window.

Not quite as general as application.run, but maybe it'll work for
you--especially if you're hardcoding the workbook's name in that application.run
statement.


AsIs wrote:

Same effect. :(
--
Чтобы знать: < http://forums.avalon.ru/forum/

"Dave Peterson" пишет:

Try dropping the ()'s in your application.run line and add a couple of "'s.

Application.Run "'Book1.xls'!Macro1", A, B



AsIs wrote:

Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Application.run and ByRef arguments

You are correct, it is ByVal.

A function can return a value, but just one with ByRef constrained.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Application.run and ByRef arguments

So, should i use user-defined type as funtion return, or create user class?
Any other desicions?
--
Alexander


"Bob Phillips" пишет:

You are correct, it is ByVal.

A function can return a value, but just one with ByRef constrained.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Application.run and ByRef arguments

I would use a function(s), and capture returned value(s).

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
So, should i use user-defined type as funtion return, or create user

class?
Any other desicions?
--
Alexander


"Bob Phillips" ?????:

You are correct, it is ByVal.

A function can return a value, but just one with ByRef constrained.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Application.run and ByRef arguments

Several functions? Hmmm...
Non procedural style.
OK. Nevertheless thanks for your advice.

--
Alexander


"Bob Phillips" пишет:

I would use a function(s), and capture returned value(s).

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
So, should i use user-defined type as funtion return, or create user

class?
Any other desicions?
--
Alexander


"Bob Phillips" ?????:

You are correct, it is ByVal.

A function can return a value, but just one with ByRef constrained.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"AsIs" wrote in message
...
Hello, all.
I want to run Macro1 from Book1.xls in Macro2 (Book2.xls).
Macro1 has two arguments ByRef:
Public Sub Macro1 (ByRef X As Integer, ByRef Y As Integer)
....
X = X * 2
Y = Y * 3
End Sub

How can I execute Macro1 with passing changed value out from Macro1.
Following code doesn't work:
A = 10
B = 20
Application.run('Book1.xls!Macro1', A, B)
I think Excel passes argyments ByVal (only value, but not reference).
--
Alexander






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
i need help with a function application with multiple arguments tarabull Excel Worksheet Functions 3 November 3rd 07 03:36 AM
application.dialogs(xlDialogPrint) - arguments David Excel Programming 0 October 17th 05 08:01 AM
passing arguments by postion through application.run ben Excel Programming 5 January 14th 05 12:22 AM
ByRef question Tommy Flynn[_2_] Excel Programming 2 November 12th 03 01:35 PM
Is ByVal always better if ByRef isn't necessary Jeff[_17_] Excel Programming 5 July 25th 03 09:25 AM


All times are GMT +1. The time now is 10:17 AM.

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

About Us

"It's about Microsoft Excel"