+ Reply to Thread
Results 1 to 2 of 2

Can I call a sub procedure from another file?

  1. #1
    Conan Kelly
    Guest

    Can I call a sub procedure from another file?

    Hello all,

    I have a time sheet workbook that, at the end of the payperiod, will
    mail itself to my boss. I want to add to it the ability to move
    itself to a "Sent" folder. But in order to do that, it needs to be
    closed. When it closes, all code stored in it after the Close method
    will not execute, correct? So, I will have to store the commands to
    close and move the file in PERSONAL.XLS. Can I call a sub procedure
    stored in PERSONAL.XLS from my timesheet workbook? If so, how?

    I'm assuming that the procedure I'm calling will need the Public
    keyword added to it, correct? I have tried that before. The
    statement I used to try to call it was:

    ProcedureName Arguments '(if any)

    But when I tried that, I got Compile Error message: Variable Not
    Defined (if I remember correctly).

    Any help on this matter will be greatly appreciated,

    Conan Kelly



  2. #2
    Dave Peterson
    Guest

    Re: Can I call a sub procedure from another file?

    This was just posted by Rob Bovey:

    Application.Run "'YourAdd-in.xla'!YourSubName", Arg1, Arg2, ....

    Just for completeness, if the routine is a function and you want to capture
    the return value, you write it as

    x = Application.Run("'YourAdd-in.xla'!YourSubName", Arg1, Arg2)

    ========
    Another alternative would be to add a reference to your workbook that points at
    your addin.

    Give your addin a nice unique project name (not VBAProject) and then with your
    other workbook's project active:

    Tools|references|
    click on that addin's project.

    Then you can use your functions/subs in the addin just like they were part of
    that same project.

    Conan Kelly wrote:
    >
    > Hello all,
    >
    > I have a time sheet workbook that, at the end of the payperiod, will
    > mail itself to my boss. I want to add to it the ability to move
    > itself to a "Sent" folder. But in order to do that, it needs to be
    > closed. When it closes, all code stored in it after the Close method
    > will not execute, correct? So, I will have to store the commands to
    > close and move the file in PERSONAL.XLS. Can I call a sub procedure
    > stored in PERSONAL.XLS from my timesheet workbook? If so, how?
    >
    > I'm assuming that the procedure I'm calling will need the Public
    > keyword added to it, correct? I have tried that before. The
    > statement I used to try to call it was:
    >
    > ProcedureName Arguments '(if any)
    >
    > But when I tried that, I got Compile Error message: Variable Not
    > Defined (if I remember correctly).
    >
    > Any help on this matter will be greatly appreciated,
    >
    > Conan Kelly


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1