Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Workbook_beforeclose +msgbox


Hi!

I'm using this code in "ThisWorkbook":

Private Sub Workbook_beforeclose(Cancel As Boolean)
Dim UserResponse As String

UserResponse = MsgBox("Remember to HIDE and PROTECT. Do you want t
save before closing?", vbYesNoCancel)
If UserResponse = vbYes Then
Me.Save
End If
If UserResponse = vbNo Then
Me.Close
End If
If UserResponse = vbCancel Then
Cancel = True
End If

End Sub


The problem is when i press "no". Then the box pops up twice....an
after pressing "no" twice excel asks again if i want to save. Why d
this happens?

Phoeni

--
Phoeni
-----------------------------------------------------------------------
Phoenix's Profile: http://www.excelforum.com/member.php...nfo&userid=292
View this thread: http://www.excelforum.com/showthread.php?threadid=27038

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Workbook_beforeclose +msgbox

Instead of just 'Me.Close' use:-

Me.Close SaveChanges:=False

Also you may not like to save again if already saved.

So Instead of just 'Me.Save', use:-

If Not Me.Saved Then Me.Save

Sharad

"Phoenix" wrote in message
...

Hi!

I'm using this code in "ThisWorkbook":

Private Sub Workbook_beforeclose(Cancel As Boolean)
Dim UserResponse As String

UserResponse = MsgBox("Remember to HIDE and PROTECT. Do you want to
save before closing?", vbYesNoCancel)
If UserResponse = vbYes Then
Me.Save
End If
If UserResponse = vbNo Then
Me.Close SaveChanges:=False
End If
If UserResponse = vbCancel Then
Cancel = True
End If

End Sub


The problem is when i press "no". Then the box pops up twice....and
after pressing "no" twice excel asks again if i want to save. Why do
this happens?

Phoenix


--
Phoenix
------------------------------------------------------------------------
Phoenix's Profile:
http://www.excelforum.com/member.php...fo&userid=2921
View this thread: http://www.excelforum.com/showthread...hreadid=270386



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbook_BeforeClose Ed Davis[_2_] Excel Discussion (Misc queries) 21 September 26th 09 01:01 AM
Workbook_BeforeClose Question Sashi Excel Worksheet Functions 7 July 26th 07 08:36 PM
Workbook_BeforeClose Don Guillett[_4_] Excel Programming 1 August 31st 04 02:27 PM
Workbook_BeforeClose JimP Excel Programming 1 July 5th 04 10:39 PM


All times are GMT +1. The time now is 01:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"