简体   繁体   English

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

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

This is what I'm trying to do. 这就是我想要做的。

  • Run macro in file x 在文件x中运行宏
  • File x macro opens file y 文件x宏打开文件y
  • Then calls file y's macro 然后调用文件y的宏
  • File y's macro runs 文件y的宏运行
  • File y closes 文件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. 我看了一下,尝试使用该线程中的信息, 在多个文件上运行excel宏 ,但这没有帮助。

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

Don't use ActiveWorkbook. 不要使用ActiveWorkbook。 Use: 采用:

 Workbooks("WorkbookName").Application.Run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM