View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Incidental Incidental is offline
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