Hi all,
is there any way to hide or disable X button (at the top right of the
window) to avoid a user to close Word?
Thanks in advance.

Mauricio
Barcelona, Spain

Re: Disable X by LtCommander

LtCommander
Wed Feb 15 01:31:46 CST 2006

You can disable the X button from the QueryClose method:

Example:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
Cancel = 1

End Sub


HTH,
Vince


Re: Disable X by Jean-Guy

Jean-Guy
Wed Feb 15 09:15:08 CST 2006

LtCommander was telling us:
LtCommander nous racontait que :

> You can disable the X button from the QueryClose method:
>
> Example:
>
> Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
> Integer)
> Cancel = 1
>
> End Sub
>
Make sure you tell the user what is going on, I would hate to click on the
X, expect the form to close, but instead, nothing happens, click again,
nothing again...

For example:

If CloseMode = vbFormControlMenu Then
MsgBox "You cant quit like that!"
Cancel = True
End If

Or tell them to use your own buttons instead.

Personally, I prefer to disable it, so visually, the user knows the X is not
functional.
See:
http://word.mvps.org/FAQs/Userforms/DisableClose.htm


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Disable X by Greg

Greg
Wed Feb 15 09:51:16 CST 2006

LtCdr/JGM

Which userform are you advising the OP to put any to this code in? He
wasn't to disable the X that closes Word. Where does he find the Word
userform?


Re: Disable X by Jean-Guy

Jean-Guy
Wed Feb 15 10:14:37 CST 2006

Greg was telling us:
Greg nous racontait que :

> LtCdr/JGM
>
> Which userform are you advising the OP to put any to this code in? He
> wasn't to disable the X that closes Word. Where does he find the Word
> userform?

Oooooopsss!
Beat me with a stick!

I am guilty of "readingtoofastisitis" I read LtCdr response, but sorta
skimmed over the OP post...

Sorry, as far as I know, you cannot disable the X on the Word window itself.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Disable X by Jonathan

Jonathan
Wed Feb 15 11:04:07 CST 2006


"Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
news:eHtwsrkMGHA.1424@TK2MSFTNGP12.phx.gbl...
> Greg was telling us:
> Greg nous racontait que :
>
>> LtCdr/JGM
>>
>> Which userform are you advising the OP to put any to this code in? He
>> wasn't to disable the X that closes Word. Where does he find the Word
>> userform?
>
> Oooooopsss!
> Beat me with a stick!
>
> I am guilty of "readingtoofastisitis" I read LtCdr response, but sorta
> skimmed over the OP post...
>
> Sorry, as far as I know, you cannot disable the X on the Word window
> itself.
>


You can disable the X, using similar techniques as for disabling the X in a
UserForm, there are just different techniques needed for identifying the
window handle for that document window.

But I think that it is hardly worth doing - there are so many ways that a
determined user can close Word that absolutely preventing it is not
possible.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


Re: Disable X by Bo

Bo
Wed Feb 15 14:12:44 CST 2006

I assume that you have your own Close button with associated code on the
user form..
Then you could use the forms Terminate event to trigger your own button:
cmdClose_Click

/BosseH





"Mauricio" <mnicastro-at-@spymac-dot.-com> skrev i meddelandet
news:%232tpLDgMGHA.3856@TK2MSFTNGP12.phx.gbl...
> Hi all,
> is there any way to hide or disable X button (at the top right of the
> window) to avoid a user to close Word?
> Thanks in advance.
>
> Mauricio
> Barcelona, Spain



Re: Disable X by Jean-Guy

Jean-Guy
Wed Feb 15 14:11:53 CST 2006

Jonathan West was telling us:
Jonathan West nous racontait que :

> "Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
> news:eHtwsrkMGHA.1424@TK2MSFTNGP12.phx.gbl...
>> Greg was telling us:
>> Greg nous racontait que :
>>
>>> LtCdr/JGM
>>>
>>> Which userform are you advising the OP to put any to this code in? He
>>> wasn't to disable the X that closes Word. Where does he find
>>> the Word userform?
>>
>> Oooooopsss!
>> Beat me with a stick!
>>
>> I am guilty of "readingtoofastisitis" I read LtCdr response, but
>> sorta skimmed over the OP post...
>>
>> Sorry, as far as I know, you cannot disable the X on the Word window
>> itself.
>>
>
>
> You can disable the X, using similar techniques as for disabling the
> X in a UserForm, there are just different techniques needed for
> identifying the window handle for that document window.

I meant through VBA...
Do you mean that there is a VBA way of doing this?
I thought it was only possible through somewhat complicated API calls.

> But I think that it is hardly worth doing - there are so many ways
> that a determined user can close Word that absolutely preventing it
> is not possible.

Very true!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Disable X by Jonathan

Jonathan
Wed Feb 15 15:31:13 CST 2006


"Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
news:uKI7RwmMGHA.2276@TK2MSFTNGP15.phx.gbl...

>>
>> You can disable the X, using similar techniques as for disabling the
>> X in a UserForm, there are just different techniques needed for
>> identifying the window handle for that document window.
>
> I meant through VBA...
> Do you mean that there is a VBA way of doing this?
> I thought it was only possible through somewhat complicated API calls.

Depends what you think of as complicated. Most of the code in this article
can be used

How to disable the X close button on a UserForm
http://word.mvps.org/FAQs/Userforms/DisableClose.htm

The key difference is that you need to get the window handle of the document
window, and use that rather than the window handle for the UserForm window.
You can get the window handle of just about any window by using the
FundWindow API call and feeding it all or part of the window caption.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


Re: Disable X by Jean-Guy

Jean-Guy
Wed Feb 15 16:27:15 CST 2006

Jonathan West was telling us:
Jonathan West nous racontait que :

> "Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
> news:uKI7RwmMGHA.2276@TK2MSFTNGP15.phx.gbl...
>
>>>
>>> You can disable the X, using similar techniques as for disabling the
>>> X in a UserForm, there are just different techniques needed for
>>> identifying the window handle for that document window.
>>
>> I meant through VBA...
>> Do you mean that there is a VBA way of doing this?
>> I thought it was only possible through somewhat complicated API
>> calls.
>
> Depends what you think of as complicated. Most of the code in this
> article can be used
>
> How to disable the X close button on a UserForm
> http://word.mvps.org/FAQs/Userforms/DisableClose.htm
>

Duh!
Must be a slow day!
Right you are, so the following, by using API stuff from VBA will dim the X
on the Word application Window:

'_______________________________________
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000

Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long

Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long

Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, _
ByVal bRevert As Long) As Long

Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private hWnd As Long

'_______________________________________
Sub DisableXinWordWindow()

Dim hMenu As Long
Dim menuItemCount As Long
Dim MyWinCaption As String

MyWinCaption = ActiveWindow.Caption & " - " & Application.Caption

'Obtain the window handle to the userform
hWnd = FindWindow(vbNullString, MyWinCaption)

'Obtain the handle to the form's system menu
hMenu = GetSystemMenu(hWnd, 0)

If hMenu Then

'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)

'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1

Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION)

'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_REMOVE Or MF_BYPOSITION)

'Force a redraw of the menu. This
'refreshes the titlebar, dimming the X

Call DrawMenuBar(hWnd)

End If

End Sub
'_______________________________________

But, as you said, that by itself is useless.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Disable X by Greg

Greg
Wed Feb 15 16:47:33 CST 2006

JGM,

No corporal punishment intended or desired (other than a few self-inflicted
blows to myself for my ever deteriorating spelling and grammar) :-(


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jean-Guy Marcil wrote:
> Greg was telling us:
> Greg nous racontait que :
>
>> LtCdr/JGM
>>
>> Which userform are you advising the OP to put any to this code in? He
>> wasn't to disable the X that closes Word. Where does he find the
>> Word userform?
>
> Oooooopsss!
> Beat me with a stick!
>
> I am guilty of "readingtoofastisitis" I read LtCdr response, but sorta
> skimmed over the OP post...
>
> Sorry, as far as I know, you cannot disable the X on the Word window
> itself.



Re: Disable X by LtCommander

LtCommander
Wed Feb 15 19:32:49 CST 2006

Guys,
Sorry! I read the original post too quickly and was immediately on a
train back to HK! Sorry real navy guy (Greg)

Vince


Re: Disable X by Jonathan

Jonathan
Thu Feb 16 12:30:32 CST 2006


"Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
news:u2Wf77nMGHA.3856@TK2MSFTNGP12.phx.gbl...

>>>
>>> I meant through VBA...
>>> Do you mean that there is a VBA way of doing this?
>>> I thought it was only possible through somewhat complicated API
>>> calls.
>>
>> Depends what you think of as complicated. Most of the code in this
>> article can be used
>>
>> How to disable the X close button on a UserForm
>> http://word.mvps.org/FAQs/Userforms/DisableClose.htm
>>
>
> Duh!
> Must be a slow day!
> Right you are, so the following, by using API stuff from VBA will dim the
> X on the Word application Window:
>

Yup, that looks about right.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org


Re: Disable X by Mauricio

Mauricio
Fri Feb 17 01:20:31 CST 2006

Bo Hansson escribió:
> I assume that you have your own Close button with associated code on the
> user form..
> Then you could use the forms Terminate event to trigger your own button:
> cmdClose_Click
>
> /BosseH
>
>
>
>
>
> "Mauricio" <mnicastro-at-@spymac-dot.-com> skrev i meddelandet
> news:%232tpLDgMGHA.3856@TK2MSFTNGP12.phx.gbl...
>> Hi all,
>> is there any way to hide or disable X button (at the top right of the
>> window) to avoid a user to close Word?
>> Thanks in advance.
>>
>> Mauricio
>> Barcelona, Spain
>
>
Thanks guys.
In order to explain better what I want to do: there is an applicattion
that communicates with Word through DDE. There are thousands of document
created with a macro inside them. Than a user wants to avoid that theirs
users close Word with the X so I have to make something. My idea was to
disable X but if you have any other idea... Keep on mind that I have to
modified each document created (not at the same time, perhaps every time
that somebody opens the doc).
I will try disabling X, for the moment.
Thanks again.

Mauricio