+ Reply to Thread
Results 1 to 9 of 9

Disabling the red X on the top right of a form.

Hybrid View

jlroper Disabling the red X on the... 09-02-2005, 06:16 AM
dominicb Good afternoon jlroper It... 09-02-2005, 08:52 AM
Guest Re: Disabling the red X on... 09-07-2005, 03:05 PM
Guest RE: Disabling the red X on... 09-02-2005, 09:05 AM
Guest Re: Disabling the red X on... 09-05-2005, 07:05 PM
Guest Re: Disabling the red X on... 09-06-2005, 05:05 AM
jlroper Worked great, thanks 09-07-2005, 07:42 AM
Guest Re: Disabling the red X on... 09-07-2005, 03:05 PM
dominicb Hi jlroper Sorry for the... 09-08-2005, 03:32 PM
  1. #1
    Registered User
    Join Date
    08-27-2005
    Posts
    6

    Disabling the red X on the top right of a form.

    Does anyone know how to disable the red X on the top right of a form?

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon jlroper

    It can be done, but only through using Windows API calls. It also makes a difference what version of Excel you are using, but the code below should handle this for you. Put this code in your main module:

    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Sub HideX(UForm As Object)
    Dim Win As Long, WinStyle As Long
    If Val(Application.Version) >= 9 Then
    Win = FindWindow("ThunderDFrame", UForm.Caption)
    Else
    Win = FindWindow("ThunderXFrame", UForm.Caption)
    End If
    WinStyle = GetWindowLong(Win, -16)
    SetWindowLong Win, -16, WinStyle And Not &H80000
    End Sub

    Sub DisplayForm()
    UserForm1.Show
    End Sub

    and in your userform module put this in your initialization routine:

    HideX UserForm1

    Just remember to include a button in there for the user to cancel...!

    HTH

    DominicB

  3. #3
    jlroper
    Guest

    Re: Disabling the red X on the top right of a form.

    Dominicb,

    When I put in the code:
    > Option Explicit
    > Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
    > (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


    I received an error that said:
    Compile error:
    Expected: line number or label or statement or end of statement
    (the third line above was red also).

    Do you know how to get around that (is that the version issue you were
    speaking about?)

    Thanks.

    "dominicb" wrote:

    >
    > Good afternoon jlroper
    >
    > It can be done, but only through using Windows API calls. It also
    > makes a difference what version of Excel you are using, but the code
    > below should handle this for you. Put this code in your main module:
    >
    > Option Explicit
    > Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
    > (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    > Private Declare Function GetWindowLong Lib "user32" Alias
    > "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    > Private Declare Function SetWindowLong Lib "user32" Alias
    > "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
    > dwNewLong As Long) As Long
    >
    > Sub HideX(UForm As Object)
    > Dim Win As Long, WinStyle As Long
    > If Val(Application.Version) >= 9 Then
    > Win = FindWindow("ThunderDFrame", UForm.Caption)
    > Else
    > Win = FindWindow("ThunderXFrame", UForm.Caption)
    > End If
    > WinStyle = GetWindowLong(Win, -16)
    > SetWindowLong Win, -16, WinStyle And Not &H80000
    > End Sub
    >
    > Sub DisplayForm()
    > UserForm1.Show
    > End Sub
    >
    > and in your userform module put this in your initialization routine:
    >
    > HideX UserForm1
    >
    > Just remember to include a button in there for the user to cancel...!
    >
    > HTH
    >
    > DominicB
    >
    >
    > --
    > dominicb
    > ------------------------------------------------------------------------
    > dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
    > View this thread: http://www.excelforum.com/showthread...hreadid=401423
    >
    >


  4. #4
    PraxisPete
    Guest

    RE: Disabling the red X on the top right of a form.

    I am no expert but try this in the code module for the UserForm
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    End If
    End Sub

    "jlroper" wrote:

    >
    > Does anyone know how to disable the red X on the top right of a form?
    >
    >
    >
    > --
    > jlroper
    > ------------------------------------------------------------------------
    > jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
    > View this thread: http://www.excelforum.com/showthread...hreadid=401423
    >
    >


  5. #5
    Jon Peltier
    Guest

    Re: Disabling the red X on the top right of a form.

    Since the user is generally trying to cancel the userform, I execute the
    cancel button code from this event. It keeps the user's annoyance level
    down.

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    CancelButton_Click
    End If
    End Sub

    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com/
    _______


    PraxisPete wrote:
    > I am no expert but try this in the code module for the UserForm
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > If CloseMode = vbFormControlMenu Then
    > Cancel = True
    > End If
    > End Sub
    >
    > "jlroper" wrote:
    >
    >
    >>Does anyone know how to disable the red X on the top right of a form?
    >>
    >>
    >>
    >>--
    >>jlroper
    >>------------------------------------------------------------------------
    >>jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
    >>View this thread: http://www.excelforum.com/showthread...hreadid=401423
    >>
    >>


  6. #6
    NickHK
    Guest

    Re: Disabling the red X on the top right of a form.

    Jon,
    Yes, I would be annoyed if the form did not act the way it (Windows) is
    designed to work.
    If it does not function, then it should not be there.

    NickHK

    "Jon Peltier" <jonREMOVExlmvp@peltierCAPStech.com> wrote in message
    news:uORFqnmsFHA.464@TK2MSFTNGP15.phx.gbl...
    > Since the user is generally trying to cancel the userform, I execute the
    > cancel button code from this event. It keeps the user's annoyance level
    > down.
    >
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > If CloseMode = vbFormControlMenu Then
    > Cancel = True
    > CancelButton_Click
    > End If
    > End Sub
    >
    > - Jon
    > -------
    > Jon Peltier, Microsoft Excel MVP
    > Peltier Technical Services
    > Tutorials and Custom Solutions
    > http://PeltierTech.com/
    > _______
    >
    >
    > PraxisPete wrote:
    > > I am no expert but try this in the code module for the UserForm
    > > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > > If CloseMode = vbFormControlMenu Then
    > > Cancel = True
    > > End If
    > > End Sub
    > >
    > > "jlroper" wrote:
    > >
    > >
    > >>Does anyone know how to disable the red X on the top right of a form?
    > >>
    > >>
    > >>
    > >>--
    > >>jlroper
    > >>------------------------------------------------------------------------
    > >>jlroper's Profile:

    http://www.excelforum.com/member.php...o&userid=26709
    > >>View this thread:

    http://www.excelforum.com/showthread...hreadid=401423
    > >>
    > >>




  7. #7
    Registered User
    Join Date
    08-27-2005
    Posts
    6

    Worked great, thanks

    That worked great thanks Mr. Peltier!

  8. #8
    jlroper
    Guest

    Re: Disabling the red X on the top right of a form.

    Hey Mr. Peltier,

    My form is automatically loaded when I click on the icon, is there a way to
    incorporate that code you gave me within the "auto_load" module or area
    (forgive me if I'm incorrect in stating that it's a module if it is not)?

    Thanks.


    "Jon Peltier" wrote:

    > Since the user is generally trying to cancel the userform, I execute the
    > cancel button code from this event. It keeps the user's annoyance level
    > down.
    >
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > If CloseMode = vbFormControlMenu Then
    > Cancel = True
    > CancelButton_Click
    > End If
    > End Sub
    >
    > - Jon
    > -------
    > Jon Peltier, Microsoft Excel MVP
    > Peltier Technical Services
    > Tutorials and Custom Solutions
    > http://PeltierTech.com/
    > _______
    >
    >
    > PraxisPete wrote:
    > > I am no expert but try this in the code module for the UserForm
    > > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    > > If CloseMode = vbFormControlMenu Then
    > > Cancel = True
    > > End If
    > > End Sub
    > >
    > > "jlroper" wrote:
    > >
    > >
    > >>Does anyone know how to disable the red X on the top right of a form?
    > >>
    > >>
    > >>
    > >>--
    > >>jlroper
    > >>------------------------------------------------------------------------
    > >>jlroper's Profile: http://www.excelforum.com/member.php...o&userid=26709
    > >>View this thread: http://www.excelforum.com/showthread...hreadid=401423
    > >>
    > >>

    >


  9. #9
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi jlroper

    Sorry for the delay in my reply - only just spotted your question from yesterday. You will probably find that the code you are copying is breaking at a certain points where Excel is expecting them to continue - probably due to the screen width on the forum you are viewing from. I've put together a small example file, just so you can see how it should look and work.

    HTH

    DominicB
    Last edited by dominicb; 08-19-2008 at 04:26 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1