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: 1
Default Close WorkBook with CommandButton

Hello,

I have a cmdbutton that I would like to use to close a workbook.
think I'm placing the procedures in the wrong area. Honestly, I'm no
sure how to set it up. The reason I say that is because I have a custo
menu with some code in Workbook_BeforeClose that duplicates excels sav
dialog box to stop the custom menu from being deleted if the user clic
on cancel. I have tried putting a call commandbutton_click() in th
Workbook_BeforeClose but, I get an error. In th
commandbutton_click(), I used Workbooks("MyFile.XLS").Close. Is thi
the right method or am I missing something? Can you even call
commandbutton? I guess that defeats the whole purpose of
commandbutton.

Here is the code I have:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

' If possible, what method would I use to call the cmdbutton?

If Not Me.Saved Then
Dim Msg As String
Dim Ans As Integer
Beep
Msg = "Do you want to save the changes you made to "
Msg = Msg & Me.Name & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
End If
Call DeleteMenu
End Sub

Rockee
Excel 200

--
Message posted from http://www.ExcelForum.com

 
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
CommandButton to open a Excel workbook aussiegirlone Excel Discussion (Misc queries) 2 March 25th 09 01:34 AM
workbook before close mohavv Excel Discussion (Misc queries) 2 November 21st 07 01:27 AM
close only one workbook bobsmom70601 New Users to Excel 1 March 8th 05 09:43 PM
How can I close only 1 workbook when I have many open? jpt consulting Excel Discussion (Misc queries) 3 November 30th 04 11:58 PM
cannot close workbook chrisneill Excel Programming 3 July 13th 03 11:10 PM


All times are GMT +1. The time now is 09:24 AM.

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"