XL 2013 Code ne fonctionne plus?

malinsard

XLDnaute Junior
Bonjour a tous je viens de passer sur Excel 2013 et le code d'un de mes module me renvoi une erreur, pouvez-vous m'aider?
ci-dessous le code en question:


Option Private Module

Declare Function GetWindowLongA Lib "User32" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long

Declare Function SetWindowLongA Lib "User32" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function FindWindowA Lib "User32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Sub SansX(USF As UserForm)
Dim hWnd As Long
hWnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", _
"X", "D") & "Frame", USF.Caption)
SetWindowLongA hWnd, -16, GetWindowLongA(hWnd, -16) And &HFFF7FFFF
End Sub
 

M12

XLDnaute Accro
Bonjour,

Quelle erreur ?
si les 3 premières lignes sont en rouge, c'est peut être que tu as une version 64 bits d'excel
si c'est le cas, il faut que tu places "PtrSafe" juste aprés "Declare"

ex: Declare PtrSafe Function
 

Roland_M

XLDnaute Barbatruc
Bonjour tout le monde,

essaies ceci et tu nous dis quoi !?

Code:
Option Private Module

#If VBA7 Then
    #If Win64 Then
        Declare PtrSafe Function GetWindowLongA Lib "USER32" Alias "GetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Declare PtrSafe Function SetWindowLongA Lib "USER32" Alias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #Else
        Declare PtrSafe Function GetWindowLongA Lib "USER32" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Declare Function SetWindowLongA Lib "USER32" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #End If
    Declare PtrSafe Function FindWindowA Lib "USER32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
    Declare Function GetWindowLongA Lib "USER32" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Declare Function SetWindowLongA Lib "USER32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Declare Function FindWindowA Lib "USER32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If

#If VBA7 And Win64 Then
    Dim hwnd As LongPtr
#Else
    Dim hwnd As Long
#End If

Sub SansX(USF As UserForm) 'suppr la croix userf avec: FindWindowA/SetWindowLongA/GetWindowLongA
hwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X", "D") & "Frame", USF.Caption)
SetWindowLongA hwnd, -16, GetWindowLongA(hwnd, -16) And &HFFF7FFFF
End Sub


EDIT: bien que c'est beaucoup plus simple et sans problème à l'avenir de faire ceci:

'ne sort pas si Click(croix) ou AltF4
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub

'et bien entendu prévoir un bouton de sortie exemple:
Private Sub CommandButton1_Click()
Unload Me
End Sub
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 508
Messages
2 089 143
Membres
104 050
dernier inscrit
Pepito93100