PDA

View Full Version : Solved: Using a String to Run a Macro



rrenis
07-11-2007, 11:29 AM
Hi all - Can anyone please advise how to acheive the following please? I can run a macro contained within a sheet by using the following...

Run "'A Workbook.xls'!MyMacro"

Unfortunately I need to refer to the workbook as a String. So I would need something like...

Run "'myWorkbook'!MyMacro"

But this doesn't work :banghead:

Can anyone please help out?

Cheers,
rrenis

mvidas
07-11-2007, 11:30 AM
You can use the & symbol to concatenate strings, like
Application.Run "'" & myWorkbook & "'!MyMacro"if myWorkbook is a workbook type variable, use myWorkbook.Name instead

rrenis
07-11-2007, 12:46 PM
Thanks - not at work at the moment but I'll try it tomorrow and let you know how it goes!! :bow:

rrenis
07-12-2007, 12:39 AM
Hi mvidas :hi:

Thanks for your help - just tried it and it works perfectly! Thank you. :bow:

Cheers,
rrenis