+ Reply to Thread
Results 1 to 4 of 4

Thread: Run macro in workbook B from a macro in Workbook A

  1. #1
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    XP 2003
    Posts
    182

    Run macro in workbook B from a macro in Workbook A

    Hi,
    I have a Workbook A where I do most of my work. I have also a Workbook B where I store data.

    I need a macro in my Workbook A that opens and run a specific macro in my workbook B.

    To open Workbook B Im using the following codes in Workbook A
    AddressB = "c:\Depot\DataStore.xls"           'DataStore.xls is the workbook B.
    Set xxDataStore =workbook.open (AddressB)     'Both lines are written in a macro in workbook A.
    Now that Workbook B is open, to run the macro in Workbook B (macro name= "DataColor") I tried:
    application.run ("DataStore.xls!DataColor"). 'This line is in a macro in Workbook A
    This last line (RUN) is not working to me. What am I doing wrong?

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Try removing the brackets
    
    Application.Run "DataStore.xls!DataColor"
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    XP 2003
    Posts
    182
    Thanks Roy.
    I tried your suggestion in a new set of workbooks and it works fine.
    But now I tried in my original documents and it sends the error 1004/(It cant find the macro).
    Do I need to write the module name between the filename and macro name?
    I already checked the filename and macro name to be sure it is not a typo.
    Do you know of any reason it couldnt find a macro if it is in there?

    I thank you very much.

  4. #4
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    XP 2003
    Posts
    182

    Thumbs up

    I found the problem.
    It looks like the run command cant handle spaces or "-" in the finename.
    In my drive, the filename has a space ("DataStore V3.xls").

    I rename the filename (in my hardrive and in the macro procedure) to "DataStoreV3.xls" and now it works fine.

    Thanks a lot Roy.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0