![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 10:58 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com