-1

This is what I'm trying to do.

  • Run macro in file x
  • File x macro opens file y
  • Then calls file y's macro
  • File y's macro runs
  • File y closes

Currently, I'm getting as far as opening file y from file x's macro, but the macro ends once file y is open and doesn't step through past opening.

I had a look and attempted using info from this thread Run excel macro on multiple files, but it didn't help.

Appreciate any help anyone can offer.

Here is the part of my code it gets to before ending. This opens file y, but ends the macro;

Workbooks.Open (MyPath & FileY & ".xls")

I want the macro to then do this;

ActiveWorkbook.Application.Run FileYsMacro

Thanks.

Community
  • 1
  • 1
chrisberry86
  • 35
  • 1
  • 1
  • 9
  • Can you post the full section of code? It *should* continue after opening the workbook. [example](http://msdn.microsoft.com/en-us/library/office/ff194819(v=office.15).aspx) – Jimmy Smith Jun 26 '14 at 15:15
  • How are you running the first macro? If it's via shortcut key combination involving the Shift key, try one that doesn't use Shift. – Rory Jun 26 '14 at 15:21
  • Does this help? http://stackoverflow.com/questions/24390156/code-error-when-called-from-another-workbook/24414952#24414952 – David Zemens Jun 26 '14 at 16:50
  • 1
    Use `Application.Run FileY & "!MacroName"` – David Zemens Jun 26 '14 at 16:51
  • 1
    @chrisberry86 Welcome to the site. It's not snobbery. this site is different than most. Take a look at this [link](http://stackoverflow.com/help/behavior) and this [link](http://stackoverflow.com/help/how-to-ask) to get the most out of using this site. The downvotes help others looking for similar help know if this is a good question. Don't get mad, edit the question to be more clear. (also, calling people snobs is not likely to get you more sympathy, instead could get you banned) – guitarthrower Jun 27 '14 at 15:40
  • And full disclosure. I've flagged your snob comment as 'rude or offensive'. Keep it nice! – guitarthrower Jun 27 '14 at 15:40
  • Fair enough, I understand. A little demotivating considering the effort, but absolutely get why everything is done how it is on the site now. Thanks. – chrisberry86 Jun 30 '14 at 12:44

1 Answers1

2

Don't use ActiveWorkbook. Use:

 Workbooks("WorkbookName").Application.Run
asp8811
  • 793
  • 8
  • 14