Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Buttons for saving and exiting a workbook

Hi

Is there any way I can either have a form button or a control box button on
my workbook, which is called Laptop Upgrades.xlsm, to:

1) save my workbook
2) and then a separate button to close and exit out of my workbook

Please let me know
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Buttons for saving and exiting a workbook

Hi Zak

You can add buttons to the sheet using Control toolbox then add the
code to that button, you could have two seperate buttons or you could
have a single button that would save and then ask the user if they
want to quit... the code for both are listed below.

'One button to save workbook
Private Sub CommandButton1_Click()

ActiveWorkbook.Save

End Sub

'One button to exit active workbook (also remove the comment mark to
have the excel app shut down also)
Private Sub CommandButton2_Click()

ActiveWorkbook.Close
'Application.Quit 'close excel

End Sub

'One button that will save and then ask the user if they wish to quit
or not
Private Sub CommandButton1_Click()

ActiveWorkbook.Save
resp = MsgBox("Do you wish to Exit?", vbInformation + vbYesNo,
"Save complete")

If resp = vbYes Then
ActiveWorkbook.Close
'Application.Quit 'close excel
Else
Exit Sub
End If

End Sub

I hope this helps you out.

Steve
  #3   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Buttons for saving and exiting a workbook

Hi

Thanks for getting back to me so soon. This code works great. Thank you
very much.



"Incidental" wrote:

Hi Zak

You can add buttons to the sheet using Control toolbox then add the
code to that button, you could have two seperate buttons or you could
have a single button that would save and then ask the user if they
want to quit... the code for both are listed below.

'One button to save workbook
Private Sub CommandButton1_Click()

ActiveWorkbook.Save

End Sub

'One button to exit active workbook (also remove the comment mark to
have the excel app shut down also)
Private Sub CommandButton2_Click()

ActiveWorkbook.Close
'Application.Quit 'close excel

End Sub

'One button that will save and then ask the user if they wish to quit
or not
Private Sub CommandButton1_Click()

ActiveWorkbook.Save
resp = MsgBox("Do you wish to Exit?", vbInformation + vbYesNo,
"Save complete")

If resp = vbYes Then
ActiveWorkbook.Close
'Application.Quit 'close excel
Else
Exit Sub
End If

End Sub

I hope this helps you out.

Steve

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
Exiting a workbook Risky Dave Excel Programming 3 September 12th 08 08:00 PM
how do i get a pop up message on saving or exiting a document? babyboos Excel Worksheet Functions 3 February 2nd 07 10:58 PM
How do I turn off saving. when I'm exiting an excel worksheet [email protected] Excel Discussion (Misc queries) 1 January 31st 06 04:22 PM
Exiting a workbook Dick Kusleika Excel Programming 0 August 15th 03 05:30 PM
Exiting a workbook John Wilson Excel Programming 0 August 15th 03 04:43 PM


All times are GMT +1. The time now is 09:18 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"