Close button and exit macro

errtu

Board Regular
Joined
Sep 23, 2010
Messages
134
So I have a workbook in which I need to disable Close button through:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
End Sub

But now it is conflicting with the procedure used to save the changes:

Code:
Sub saveas_city_m()
AllFilled = True
For Each cll In Range("B4:B6").Cells
  If Not cll.Value > 0.1 Then
    AllFilled = False
    Exit For
  End If
Next cll
If AllFilled Then
  For Each cll In Range("D13:D17").Cells
    If cll.Value > 0.1 Then
      If Not cll.Offset(, 1) > 0.1 Then
        AllFilled = False
        Exit For
      End If
    End If
  Next cll
End If
If AllFilled Then
  ActiveWorkbook.SaveAs "C:\Users\K\Desktop\tryOuts\23\city m.xlsm", FileFormat:=52
  MyFile = "C:\Users\K\Desktop\tryOuts\CITY M.xlsm"
  Kill MyFile
  Application.Quit
  Else
  MsgBox "Can not save. Complete Cell: " & cll.Offset(, 1).Address(False, False)
End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Rich (BB code):
Sub saveas_city_market()
AllFilled = True
For Each cll In Range("B4:B6").Cells
  If Not cll.Value > 0.1 Then
    AllFilled = False
    Exit For
  End If
Next cll
If AllFilled Then
  For Each cll In Range("D13:D17").Cells
    If cll.Value > 0.1 Then
      If Not cll.Offset(, 1) > 0.1 Then
        AllFilled = False
        Exit For
      End If
    End If
  Next cll
End If
If AllFilled Then
  Application.EnableEvents = False
  ActiveWorkbook.SaveAs "C:\Users\Khaos\Desktop\tryOuts\23\city market.xlsm", FileFormat:=52
  MyFile = "C:\Users\Khaos\Desktop\tryOuts\CITY MARKET.xlsm"
  Kill MyFile
  Application.Quit
  Else
  MsgBox "No se puede guardar. Completar Celda: " & cll.Offset(, 1).Address(False, False)
End If
End Sub
 
Last edited:
Upvote 0
Sorry, I didn't see your previous post.

This worked for me:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Cancel = True
End Sub
 
Sub Test()
    Application.EnableEvents = False
    ThisWorkbook.Saved = True
    Application.Quit
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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