Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run macros (2003 SP2)

    Can I have my master file open a target file and then run code from within the target file? I don't want the code to run every time the target file is opened, just when it is opened by the master file, therefore I don't want to use the workbook_open() procedure.
    Can this be done?
    Thanks for your help!

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Run macros (2003 SP2)

    How about this recent post <post:=642,332>post 642,332</post:> is this indicative?
    Jerry

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run macros (2003 SP2)

    If you only want to run the code when the target file is opened from the master file, it would make more sense to put the code in a module in the master file.

    If you have other reasons for storing the code in the target file, you can use Application.Run:
    <code>
    Application.Run "'My File.xls'!Module1.MyCode"
    </code>
    Where My File.xls is the name of the target workbook, Module1 the name of the module and MyCode the name of the macro you want to run.

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run macros (2003 SP2)

    Brilliant solution - many thanks. Works perfectly!
    If anyone else is reading this as well, I used a variable (fname) to get the file name and the code was in Module 2, so the syntax of the command in this situation is:

    fname = Dir(newfn) 'to get the name of the file without the path
    Application.Run "'" & fname & "'!Module2.MyCode"

    Thanks again Hans

Posting Permissions

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