Consulting

Results 1 to 4 of 4

Thread: Running a macro in another workbook

  1. #1

    Running a macro in another workbook

    Hey Folks.
    Kindofa continuation from a prior solved post.
    WIth two workbooks open, I'm trying to execute the following command from "workbook1.xls" to run a macro in a different workbook "Myfile(Orders).xls":

    Application.Run "Myfile(Orders)!TestMyClass"
    This command works fine with a regular file name, however if the filename has any characters that are illegal for a macro (i.e. parentheses) it blows up. I could rename the files that are to be run, however I'd rather not. I tried playing around with the workbooks.Item to get the id

    Workbooks(WkbkId).Application.Run ("TestMyClass")
    - to no avail.
    It's quite possible that I may just have to bite the bullet and rename a bunch of files. Any ideas?
    Thanks
    AK

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Akinator,

    I fought this myself a couple of years ago!

    Try putting single quotes around the workbook name (before the !)

    ie:

    Application.Run "'Myfile(Orders)'!TestMyClass"
    I think that should do it for you.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Ken that did it! I swear that must be the only combination of things that I didn't try.
    You guys on this site are really great - thanks!

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Great, glad it helped! And thanks for the site compliment!

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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