[英]Closing Workbook after opening it through VBA - Excel
I have the code below. 我有下面的代码。 I've called the excel document from a VBA code.
我已经从VBA代码中调用了excel文档。 However, after pressing the closing button on the workbook, it doesn't close until I stop the macro.
但是,按下工作簿上的关闭按钮后,直到我停止宏,它才会关闭。 I want to be able to close the document without stopping the macro.
我希望能够在不停止宏的情况下关闭文档。 ie the main userform is still running behind.
即主要用户窗体仍在运行。 I can close the excel workbook from the close button top right of the workbook itself.
我可以从工作簿本身右上角的关闭按钮关闭excel工作簿。
Anyone happen to know how to solve this? 有人碰巧知道如何解决这个问题吗?
Private Sub CommandButton7_Click()
Workbooks("master system.xlsm").Activate
Workbooks.Open ActiveWorkbook.Path & "\Toolbox\Define\PPST.xlsx"
End Sub
Try Workbooks("PPST.xlsx").Close SaveChanges:=True
试试
Workbooks("PPST.xlsx").Close SaveChanges:=True
This is from the documentation enter link description here 这是从文档中输入链接描述的
Try scattering DoEvents
throughout your code after opening the workbook. 打开工作簿后,尝试在整个代码中分散
DoEvents
。
Just be aware that if you depend on the ActiveWorkbook
or Selection
objects in your code, they could change after DoEvents
. 请注意,如果您依赖代码中的
ActiveWorkbook
或Selection
对象,则它们可能在DoEvents
之后更改。
DoEvents
essentially tells your code to pause, and let Excel do other, waiting tasks -- such as allowing the user to select cells, and probably closing a workbook -- before continuing. DoEvents
本质上告诉您的代码暂停,然后让Excel执行其他等待的任务-例如,允许用户选择单元格,并可能关闭工作簿-然后再继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.