Consulting

Results 1 to 5 of 5

Thread: Exchanging argument values between macros in different wokbooks

  1. #1

    Exchanging argument values between macros in different wokbooks

    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    aaa = 3
    bbb = Application.Run("Book1!addtest", aaa)
    [/vba]

    [vba]

    Function addtest(a)
    addtest = a * 3
    End Function
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •