1
votes

I have the code below. I've called the excel document from a VBA code. 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. i.e. the main userform is still running behind. I can close the excel workbook from the close button top right of the workbook itself.

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
2
It may help if you state what you want to achieve/why....dv3

2 Answers

0
votes

Try Workbooks("PPST.xlsx").Close SaveChanges:=True

This is from the documentation enter link description here

0
votes

Try scattering DoEvents throughout your code after opening the workbook.

Just be aware that if you depend on the ActiveWorkbook or Selection objects in your code, they could change after 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.