OVH Cloud OVH Cloud

Interdire la fermeture d'un userform par la croix

6 réponses
Avatar
Alpha
Bonsoir
Je désire interdire la fermeture d'un userform par la croix
j'ai récupéré une proc sur Excelabo.net, mais celle-ci ne fonctionne pas.
Merci beaucoup
Alpha

6 réponses

Avatar
docmarti
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la croix
j'ai récupéré une proc sur Excelabo.net, mais celle-ci ne fonctionne pas.
Merci beaucoup
Alpha





Avatar
Alpha
Merci beaucoup Docmarti,
cela fonctionne très bien,
une p'tite dernière peut-on supprimer la barre de titre
d'un userform ?
Alpha

-----Message d'origine-----
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la
croix


j'ai récupéré une proc sur Excelabo.net, mais celle-ci
ne fonctionne pas.


Merci beaucoup
Alpha






.




Avatar
michdenis
Bonjour Alpha,

Dans ton formulaire :

'Section déclaration API à mettre dans le haut de ton module formulaire

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
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
' Pour pouvoir déplacer l'UserForm avec clic gauche maintenu
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function EnableWindow Lib "user32" _
(ByVal hWnd As Long, ByVal fEnable As Long) As Long


Private Sub UserForm_Initialize()
Dim hWnd As Long, Style As Long

hWnd = FindWindow(vbNullString, Me.Caption)
Style = GetWindowLong(hWnd, -16) And Not &HC00000
SetWindowLong hWnd, -16, Style
DrawMenuBar hWnd
End Sub



Salutations!



"Alpha" a écrit dans le message de news:1416501c3c31a$359ec730$
Merci beaucoup Docmarti,
cela fonctionne très bien,
une p'tite dernière peut-on supprimer la barre de titre
d'un userform ?
Alpha

-----Message d'origine-----
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la
croix


j'ai récupéré une proc sur Excelabo.net, mais celle-ci
ne fonctionne pas.


Merci beaucoup
Alpha






.




Avatar
docmarti
Bonjour Alpha.

Je cite la réponse donnée par Michel Pierron:

Il t'en couteras l'utilisation de quelques fonctions API.
Dans le module de ton UserForm:

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
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As
Long

Private Sub UserForm_Initialize()
Dim hWnd As Long, Style As Long

hWnd = FindWindow(vbNullString, Me.Caption)
Style = GetWindowLong(hWnd, -16) And Not &HC00000
SetWindowLong hWnd, -16, Style
DrawMenuBar hWnd
End Sub

Bien évidemment, tu ne pourras plus dans ce cas déplacer ton UserForm avec
la souris.



"Alpha" wrote in message
news:1416501c3c31a$359ec730$
Merci beaucoup Docmarti,
cela fonctionne très bien,
une p'tite dernière peut-on supprimer la barre de titre
d'un userform ?
Alpha

-----Message d'origine-----
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la
croix


j'ai récupéré une proc sur Excelabo.net, mais celle-ci
ne fonctionne pas.


Merci beaucoup
Alpha






.




Avatar
Alpha
Merci beaucoup Denis
Alpha

"michdenis" a écrit dans le message de news:

Bonjour Alpha,

Dans ton formulaire :

'Section déclaration API à mettre dans le haut de ton module formulaire

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

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

' Pour pouvoir déplacer l'UserForm avec clic gauche maintenu
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function EnableWindow Lib "user32" _
(ByVal hWnd As Long, ByVal fEnable As Long) As Long


Private Sub UserForm_Initialize()
Dim hWnd As Long, Style As Long

hWnd = FindWindow(vbNullString, Me.Caption)
Style = GetWindowLong(hWnd, -16) And Not &HC00000
SetWindowLong hWnd, -16, Style
DrawMenuBar hWnd
End Sub



Salutations!



"Alpha" a écrit dans le message de
news:1416501c3c31a$359ec730$

Merci beaucoup Docmarti,
cela fonctionne très bien,
une p'tite dernière peut-on supprimer la barre de titre
d'un userform ?
Alpha

-----Message d'origine-----
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la
croix


j'ai récupéré une proc sur Excelabo.net, mais celle-ci
ne fonctionne pas.


Merci beaucoup
Alpha






.








Avatar
Alpha
Merci beaucoup Docmarti
Alpha

"docmarti" a écrit dans le message de news:
#
Bonjour Alpha.

Je cite la réponse donnée par Michel Pierron:

Il t'en couteras l'utilisation de quelques fonctions API.
Dans le module de ton UserForm:

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

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

Private Sub UserForm_Initialize()
Dim hWnd As Long, Style As Long

hWnd = FindWindow(vbNullString, Me.Caption)
Style = GetWindowLong(hWnd, -16) And Not &HC00000
SetWindowLong hWnd, -16, Style
DrawMenuBar hWnd
End Sub

Bien évidemment, tu ne pourras plus dans ce cas déplacer ton UserForm avec
la souris.



"Alpha" wrote in message
news:1416501c3c31a$359ec730$
Merci beaucoup Docmarti,
cela fonctionne très bien,
une p'tite dernière peut-on supprimer la barre de titre
d'un userform ?
Alpha

-----Message d'origine-----
Bonjour.
Voici qui devrait fonctionner.

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Empêche l'utilisation du Bouton de fermeture
If CloseMode = vbFormControlMenu Then
MsgBox "Le Bouton de fermeture est désactivé."
Cancel = True
End If
End Sub


"Alpha" wrote in message
news:
Bonsoir
Je désire interdire la fermeture d'un userform par la
croix


j'ai récupéré une proc sur Excelabo.net, mais celle-ci
ne fonctionne pas.


Merci beaucoup
Alpha






.