PDA

View Full Version : [SOLVED] Running a macro in another workbook



akinator
07-21-2005, 11:52 AM
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

Ken Puls
07-21-2005, 12:00 PM
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,

akinator
07-21-2005, 12:13 PM
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!

Ken Puls
07-21-2005, 12:32 PM
Great, glad it helped! And thanks for the site compliment!

:hi: