UserForm CommandButton1

geno32080

Board Regular
Joined
Jan 23, 2020
Messages
107
Office Version
  1. 2013
Platform
  1. Windows
I created a UserForm that shows from a command button on a sheet, On that userform it asks the user to Close the program(comandbutton1) or cancel (commandbuttomn2 when cancel is clicked it hides the userform). if the user selects close i would like for it to show the contents in label1. on the userform then save and close the program, I cant get it to work with the selections vba offers,
Any Ideas what to put after the Label1? to make that work? Thank you.

1641659445796.png
1641659525561.png
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
See if this approach works for you. It doesn't use the label on the userform. When you click "OK" after the message box appears, Excel will close.
VBA Code:
Private Sub CommandButton1_Click()
    Unload UserForm2
    ThisWorkbook.Save
    MsgBox "The sheets have been saved."
    Application.Quit
End Sub
 
Upvote 0
See if this approach works for you. It doesn't use the label on the userform. When you click "OK" after the message box appears, Excel will close.
VBA Code:
Private Sub CommandButton1_Click()
    Unload UserForm2
    ThisWorkbook.Save
    MsgBox "The sheets have been saved."
    Application.Quit
End Sub
Thanks, I started off with that, but as we all do, we want more. I did a VBA Script and a Userform to open the program to rid the excel splash screen, it looks good, was hoping to be able to do something like that to close the program.
 
Upvote 0
Is this what you are trying?

VBA Code:
Option Explicit

Private Sub CommandButton1_Click()
    Label1.Caption = "Saving Sheets"
   
    '~~> Wait for 3 seconds. Change as applicable
    Wait 3
   
    ThisWorkbook.Save
   
    Unload Me
   
    Application.Quit
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub
 
Upvote 0
Solution
Is this what you are trying?

VBA Code:
Option Explicit

Private Sub CommandButton1_Click()
    Label1.Caption = "Saving Sheets"
  
    '~~> Wait for 3 seconds. Change as applicable
    Wait 3
  
    ThisWorkbook.Save
  
    Unload Me
  
    Application.Quit
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub
Get that man a Cigar.. I didn't need to say UserForm.Label1. Just Label1.Caption... That worked. Thank you..
 
Upvote 0

Forum statistics

Threads
1,214,552
Messages
6,120,172
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top