ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Userform + close button (https://www.excelbanter.com/excel-discussion-misc-queries/80941-userform-close-button.html)

Chip Smith

Userform + close button
 
i have a user form and when you click the "Close" button at the bottom it
closes out of the macro/userform it looks like this right now..

Private Sub cmdClose2_Click()
Unload Me
End Sub

what can i add to this sub so that when the button is clicked it

1. saves the workbook
2. closes the worksheet/exit out of excel

thanks!

--
--Chip Smith--


Kevin B

Userform + close button
 

Just add the following to your code:

Unload Me
ActiveWorkbook.Save
Application.Quit

--
Kevin Backmann


"Chip Smith" wrote:

i have a user form and when you click the "Close" button at the bottom it
closes out of the macro/userform it looks like this right now..

Private Sub cmdClose2_Click()
Unload Me
End Sub

what can i add to this sub so that when the button is clicked it

1. saves the workbook
2. closes the worksheet/exit out of excel

thanks!

--
--Chip Smith--


Harald Staff

Userform + close button
 
Hi Chip

What happens if the user has more than your file open in Excel ? Don't do
that.

Best wishes Harald

"Chip Smith" skrev i melding
...
i have a user form and when you click the "Close" button at the bottom it
closes out of the macro/userform it looks like this right now..

Private Sub cmdClose2_Click()
Unload Me
End Sub

what can i add to this sub so that when the button is clicked it

1. saves the workbook
2. closes the worksheet/exit out of excel

thanks!

--
--Chip Smith--





All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com