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
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,397
Office Version
365, 2019, 2016, 2010
Platform
Windows, 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
35,397
Office Version
365, 2019, 2016, 2010
Platform
Windows, 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
803

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
35,397
Office Version
365, 2019, 2016, 2010
Platform
Windows, 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
35,397
Office Version
365, 2019, 2016, 2010
Platform
Windows, 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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,616
Messages
5,512,428
Members
408,893
Latest member
Abdulmemon

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top