Consulting

Results 1 to 4 of 4

Thread: Solved: Using a String to Run a Macro

  1. #1

    Solved: Using a String to Run a Macro

    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...

    [VBA]Run "'A Workbook.xls'!MyMacro"[/VBA]

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

    [VBA]Run "'myWorkbook'!MyMacro"[/VBA]

    But this doesn't work

    Can anyone please help out?

    Cheers,
    rrenis

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    You can use the & symbol to concatenate strings, like
    [vba]Application.Run "'" & myWorkbook & "'!MyMacro"[/vba]if myWorkbook is a workbook type variable, use myWorkbook.Name instead
    Matt

  3. #3
    Thanks - not at work at the moment but I'll try it tomorrow and let you know how it goes!!

  4. #4
    Hi mvidas

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

    Cheers,
    rrenis

Posting Permissions

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