Code stops after ActiveWIndow.Close?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
417
Office Version
  1. 2007
Platform
  1. Windows
Hello,

I’m having a small issue with my routine stopping after one line of code. It stops after
ActiveWindow.Close savechanges:=False
It never processes anything after this (e.g., I do not see the message box). If I remark out the line above, the routine continues through the message box. Any suggestions would be appreciated.

Following is a snipit (test) of my code:
VBA Code:
Public Sub Repair_NO()
   Workbooks.Open("C:\Users\Steven Kipping\Desktop\5407.xlsb").RunAutoMacros Which:=xlAutoOpen
   Windows("Amort_Temp1.xlsb").Activate
   ActiveWindow.Close savechanges:=False
   Kill "C:\Users\Steven Kipping\Desktop\test.xlsb"
   MsgBox "Try_MSG"
End Sub

Thanks for viewing,
Steve K.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Of course it does, if the workbook containing the code happens to be that active workbook that you are asking to close. Excel cannot run code that is in a closed workbook so it all stops with that statement.
 
Upvote 0
Of course it does, if the workbook containing the code happens to be that active workbook that you are asking to close. Excel cannot run code that is in a closed workbook so it all stops with that statement.
Thank you Jan for your quick response.
That does make sense. So is there a way to call the remaining part of the code (or some other code) from the remaining open workbook (i.e., 5407.xlsb)? If not, what I've been doing is running the "Kill" command from Workbook_BeforeClose routing. If possible, I just rather do it before closing all.

VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   On Error Resume Next
   Kill ActiveWorkbook.Path & Application.PathSeparator & "Amort_Temp*.xlsb"
End Sub

Sorry for asking such mundane questions - as you can tell, I am not a programmer.
 
Upvote 0
I believe I have this resolved. There are other command buttons on the form that are used quite often. In addition to the Workbook_BeforeClose sub, I have added this code to a couple other buttons. It appears to be doing what I want.

VBA Code:
On Error Resume Next
Kill ActiveWorkbook.Path & Application.PathSeparator & "Amort_Temp*.xlsb"

Thanks all,
Steve K.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top