prompt save only when changes have been made

LFKim2018

Active Member
Joined
Mar 24, 2018
Messages
267
whenever I close a workbook, even though no changes have been made, a message box prompt to save or not almost always appear.

I want the workbook to prompt only when there are changes made - and close right away when there are not (no prompt nor message box)..

thank you
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The conclusions:

1. Me.Saved should be the bottom code line of Workbook_Open().
2. StartBlink() subroutine periodically changes interior color of the cell Form!G32, StopBlink() do the same once, and Excel treats it as workbook changing. That is why the saving dialog is appeared. Solution can be in storing of Thisworkbook.Saved status before changing cell's color and restoring that status after the changing.

I've sent you back the fixed workbook with code changed in those subroutines:
ThisWorkbook.Workbook_Open
ThisWorkbook.Workbook_BeforeClose
Module5.StartBlink
Module5.StopBlink
Sheet20.Worksheet_Change

The mentioned code looks like the follows:
Rich (BB code):
' Code of ThisWorkbook module
Private Sub Workbook_Open()
  ' Your code is here
  '...
  Me.Saved = True
End Sub
 
Private Sub Workbook_BeforeClose(CANCEL As Boolean)
  ' Your code is here
  '...
  StopBlink
End Sub

Rich (BB code):
' Code of Module5
Public rRange As Range  ' Sheet20.Range("G32")
Dim dNextTime As Double
 
Sub StartBlink()
  Dim IsSaved As Boolean
  On Error GoTo ErrorHandle
  IsSaved = ThisWorkbook.Saved  ' Save status
  With rRange.Interior
    If .ColorIndex = 15 Then
      .ColorIndex = xlNone
    Else
      .ColorIndex = 15
    End If
  End With
  ThisWorkbook.Saved = IsSaved  'Restore status
  dNextTime = Now + TimeSerial(0, 0, 1)
  Application.OnTime dNextTime, "StartBlink", , True
  Exit Sub
ErrorHandle:
  MsgBox Err.Description & " Procedure StartBlink."
  Set rRange = Nothing
End Sub
 
Sub StopBlink()
  Dim IsSaved As Boolean
  IsSaved = ThisWorkbook.Saved  ' Save status
  On Error Resume Next
  Application.OnTime dNextTime, "StartBlink", , False
  rRange.Interior.ColorIndex = xlNone
  Set rRange = Nothing
  ThisWorkbook.Saved = IsSaved  ' Restore status
End Sub

Rich (BB code):
' Code of Sheet20 - Sheets("Form")
Private Sub Worksheet_Change(ByVal Target As Range)
 
  Dim IsSaved As Boolean
  IsSaved = ThisWorkbook.Saved  ' Save status
 
  ' Your code is here:
  Sheets("E-L1").Visible = ([C3] > 0 And [B3] > 0 And [B1] > 0)
  ' ... and so on ..
 
 
  ThisWorkbook.Saved = IsSaved  ' Restore status
 
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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