Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Running Code from Another Workbook (03)

    I am running into an run time error message 1004 when I try to run code from another workbook.

    The code I am using is: Application.Run "MyFile.xls!Module1.MyCode"

    The error message is: The Macro 'MyFile.xls!Module1.MyCode' cannot be found.

    If I go to the module, I can run the code successfully. I did check to see if the file name was spelled correctly and it is.

    Any ideas as to why?

    Thanks,
    John

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

    Re: Running Code from Another Workbook (03)

    Is MyFile.xls open when you try this?

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code from Another Workbook (03)

    Yes it is.

    Regards,
    John

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

    Re: Running Code from Another Workbook (03)

    Is the line of code you mention the exact code you used, or just an example? If the real name of the workbook contains spaces or unusual characters, you must enclose the name in single quotes:
    <code>
    Application.Run "'My File.xls'!Module1.MyCode"</code>

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code from Another Workbook (03)

    Hans,

    I do not have any spaces in the file name. However I took your suggestion by enclosing the name in single quotes and it worked.

    Thank you,
    John

  6. #6
    3 Star Lounger
    Join Date
    Mar 2003
    Location
    Beddau, Mid Glamorgan, Wales
    Posts
    289
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running Code from Another Workbook (03)

    John:

    If the file name contains any non-alphanumeric characters, the enclosing single quotes are also required.

    Tony
    Regards,

    Tony
    [s] [/s]
    www.SylviArtist.com

Posting Permissions

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