Problème cadre userform
Bonjour, j'ai trouvé ce code pour supprimer le cadre de mon userform mais ça me mets en erreur les founctions :
Option Explicit
'Pour enlever la barre de titre du UF
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Const GWL_STYLE = (-16)
Public Const WS_CAPTION = &HC00000
Public Const SWP_FRAMECHANGED = &H20
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Sub OteTitleBarre(stCaption As String, pbVisible As Boolean)
Dim vrWin As RECT
Dim style As Long
Dim lHwnd As Long
'- Recherche du handle de la fenêtre par son Caption
lHwnd = FindWindowA(vbNullString, stCaption)
If lHwnd = 0 Then
MsgBox "Handle de " & stCaption & " Introuvable", vbCritical
Exit Sub
End If
GetWindowRect lHwnd, vrWin
style = GetWindowLong(lHwnd, GWL_STYLE)
If pbVisible Then
SetWindowLong lHwnd, GWL_STYLE, style Or WS_CAPTION
Else
SetWindowLong lHwnd, GWL_STYLE, style And Not WS_CAPTION
End If
SetWindowPos lHwnd, 0, vrWin.Left, vrWin.Top, vrWin.Right - vrWin.Left, _
vrWin.Bottom - vrWin.Top, SWP_FRAMECHANGED
End Sub
Bonjour,
tu as mis ce code où ? place le dans un nouveau module .. Et si tu as encore des erreurs commence par lire les "messages d'erreurs" pour pouvoir nous les rapporter..
je l' ai déja mis dans un nouveau module, le probleme viendrait du fait que j'utilise excel 64 bits
Bonjour à tous,
Les fonctions de la librairy "user32" sont conçues pour les PC 32 bits. En cas d'utilisation sur un PC 64 bits, il faut faire précéder la fonction par un Ptrsafe :
Public Declare PtrSafe Function ...
En cas d'écriture de code pour une appli devant être utilisée indifféremment sur 32 et/ou 64 bits, il faut ajouter une option de compilation conditionnelle, par exemple :
#If VBA7 Then
Public Declare PtrSafe Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' ...
#Else
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' ...
#End If
Pierre
PS : attention à ne pas confondre PC 32 ou 64 bits et Office 32 ou 64 bits , on peux avoir un PC 64bits avec office 32bits ... (ce qui est plutôt à conseiller en général)
ça fonctionne parfaitement, un grand merci à vous pour vos aides