VBA Code Macros

Bradley H Callender

Board Regular
Joined
Aug 5, 2010
Messages
120
How can I keep a user form up until it is used. For example i don't want the user to just close it please give me a macro code for that
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
We need more information. What does the form do? Is there a button on it that has to be pressed?
 

Bradley H Callender

Board Regular
Joined
Aug 5, 2010
Messages
120
The form just has 3 buttons

open this workbook - which would ask for user info
Workbook instructions - a list of instructtions about the workbook
close this work - which would unload the form and close excel

i want the person not to click the "x" as soon as the workbook opens i want them use the buttons.

so is there a timer or loop i can put on that "x" (close)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Are you talking about the X on the form, or the workbook or Excel window?
 

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
833

ADVERTISEMENT

Try this code
Code:
Private Sub UserForm_QueryClose _
  (Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        MsgBox "Clicking the Close button does not work."
        Cancel = True
    End If
End Sub
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

If you show the form modally (the default) then they have to close the userform before they can do anything.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Walk you through what exactly? What code do you have currently to show the form?
 

Bradley H Callender

Board Regular
Joined
Aug 5, 2010
Messages
120
I only have :

Private Sub Workbook_Open()
Workbookcontrol.Show
End Sub


Thats for auto open but i want to prevent the user form using the "X" to close the whole window
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,109
Messages
5,857,441
Members
431,879
Latest member
KiwDaWabbit

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
Top