PDA

View Full Version : Exchanging argument values between macros in different wokbooks



IlarioAstino
08-14-2010, 12:59 PM
Hi everybody! Saturday night, instead of talking ladies I am having the following problem:

- I have say this macro in personal.xls:
sub addtest(a, b)
b = a * 3
end Sub

- from a different workbook (say testbook.xls) I am calling the procedure as follows:

aaa = 3
application.run "personal.xls!addtest", aaa, bbb

...and I receive an "empty" value in bbb!!

any clue what I am messing up?

Bob Phillips
08-14-2010, 02:25 PM
aaa = 3
bbb = Application.Run("Book1!addtest", aaa)




Function addtest(a)
addtest = a * 3
End Function

IlarioAstino
08-14-2010, 02:28 PM
Hey, that is great! But I want to use a Sub, not a Function - because in some cases I will need to retyrn 2 or mode raguments i.e.:

sub aaa(a, b, c)
b = 2 * a
c = 3 * a
end Sub

Bob Phillips
08-14-2010, 03:14 PM
Unfortunately, in Application.Run, all arguments are passed by value, so you cannot do it directly. You would have to frig it some way, maybe call the function multiple times passing the particular value type to be returned, and a first run parameter (so the function does its stuff that time).

IlarioAstino
08-14-2010, 03:24 PM
Tx XLD - will see how life will go one. If I get some ideaw ofcourse will post them here. Nice day. I think visiting my bed...