Excel VBA - 运行宏/打开另一个文件/运行该文件宏/保存并关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24434011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:24:05  来源:igfitidea点击:

Excel VBA - Run Macro / Open another file / Run that files macro / Save & Close

excelvbaexcel-vba

提问by chrisberry86

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
  • 在文件 x 中运行宏
  • 文件 x 宏打开文件 y
  • 然后调用文件 y 的宏
  • 文件 y 的宏运行
  • 文件 y 关闭

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.

目前,我正在从文件 x 的宏中打开文件 y,但是一旦文件 y 打开,宏就会结束,并且不会跳过过去的打开。

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

我查看并尝试使用此线程中的信息Run excel macro on multiple files,但没有帮助。

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;

这是我的代码在结束之前到达的部分。这将打开文件 y,但结束宏;

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

I want the macro to then do this;

我希望宏然后执行此操作;

ActiveWorkbook.Application.Run FileYsMacro

Thanks.

谢谢。

回答by asp8811

Don't use ActiveWorkbook. Use:

不要使用 ActiveWorkbook。用:

 Workbooks("WorkbookName").Application.Run