LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Workbook_BeforeClose problem

Hi
In this part of the code

exitmessage = "Do you want to save the changes you made to " &
Range("c10") & Range("c7") & ".xls"


which workbook are these range references from ?
They could be from the active book, which is not currently
Lead ATSM Ver3.51.xls

This may cause a problem.

HTH
Andrew Bourke


broogle wrote:
What is wrong with this code? Please help?

This code will prompt user with "Yes No Cancel", user can choose to
exit and save the activeworkbook (file name will be taken from certain
cells) or exit without saving it.
My problem is the code will run twice before it close, this is because
I make enableevents = true before it close. If I make enableevents =
false, the next time I open another spreadsheet the code will not be
activated. (Apologise for my bad english). Thanks

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.DisplayAlerts = False

Application.EnableEvents = False
If ThisWorkbook.Name = "Lead ATSM Ver3.51.xls" Then
ActiveWorkbook.Close (False)
Else
Dim exitmessage, msg, response As String

exitmessage = "Do you want to save the changes you made to " &
Range("c10") & Range("c7") & ".xls"

response = MsgBox(exitmessage, vbYesNoCancel)

If response = vbNo Then

ActiveWorkbook.Close (False)
Else

If response = vbYes Then


ActiveWorkbook.SaveCopyAs filename:= _
"C:\Temp" & "\" & Range("c10") & Range("c7") & ".xls"

msg = "File was saved as C:\Temp\" & Range("c10") &
Range("c7") & ".xls"
response = MsgBox(msg, vbExclamation)
Application.EnableEvents = True

ActiveWorkbook.Close (False)

Exit Sub
Else

Cancel = True

End If
End If
End If


End Sub

 
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 PO Excel Programming 2 January 30th 05 05:07 PM
Workbook_BeforeClose JimP Excel Programming 1 July 5th 04 10:39 PM
Workbook_BeforeClose problem Amit Shanker Excel Programming 6 May 22nd 04 12:07 AM


All times are GMT +1. The time now is 05:33 PM.

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

About Us

"It's about Microsoft Excel"