Boostez vos compétences Excel avec notre communauté !
Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !
division par zéro sur cette ligne:re
ne pas en vouloir à cathodique il a fait confiance en chat gpt
et les modifs de chatgpt sont stupéfiantes tellement c'est stupide
c'est incroyable comme chatgpt a tricoté mon code simple ou il fallait seulement ajouter les déclaration 64 en un truc sans nom
je suis estomaqué
allez
je vous donne le vieux machin pour ceux pour qui ca pesent trop de devoir se depatouiller avec les déclarations d'api
VB:'***************************************************************************************************** ' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _. ' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| // ' //___// //__\ // //__// // // //__// // // // // // // // // // | // ' // // \\ // // \\ // // // \\ // // // // // // // // // | // '// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |// '**************************************************************************************************** ' Module RESIZER userform version basic 'version avec api en macro 4 'release 2020 for XLD '**************************************************************************************************** Option Explicit Dim OldW#, OldH# Sub trois_boutons1() 'ajoute les 3 boutons et le resize dynamique à l'userform Dim hWnd& hWnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'api GetActiveWindow ExecuteExcel4Macro ("CALL(""user32"",""SetWindowLongA"",""JJJJJ""," & hWnd & ", " & -16 & ", " & &H94CF0080 & ")") 'api SetWindowLongA End Sub Sub NoTitleBar1() 'supprime la barre de titre( rempli absolument tout l'ecran Dim hWnd& hWnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'api GetActiveWindow ExecuteExcel4Macro ("CALL(""user32"",""SetWindowLongA"",""JJJJJ""," & hWnd & ", " & -16 & ", " & &H140F0101 ")") 'api SetWindowLongA End Sub Sub UsfFullScreen1() 'met le userform en plein ecran Dim hWnd& hWnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'api GetActiveWindow ExecuteExcel4Macro ("CALL(""user32"",""ShowWindow"",""JJJ""," & hWnd & ", 3)") 'api SetWindowLongA End Sub Sub memoControlSize1(usf) 'on memorise dans le tag des controls leur position et dimension Dim CtrL OldW = usf.Width OldH = usf.Height For Each CtrL In usf.Controls CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height On Error Resume Next CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size CtrL.Tag = CtrL.Tag & ";" Err.Clear: On Error GoTo 0 If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|") End If CtrL.Tag = CtrL.Tag & ";" Next End Sub Sub resiZer1(usf) Dim newW#, NewH#, t, cw$, tc, CtrL, i& newW = usf.Width / OldW NewH = usf.Height / OldH For Each CtrL In usf.Controls t = Split(CtrL.Tag, ";") CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then If CtrL.ColumnWidths = "" Then cw = Application.Rept("80", CtrL.ColumnCount) Else cw = CtrL.ColumnWidths tc = Split(t(6), "|") For i = 0 To UBound(tc): tc(i) = Val(tc(i)) * Application.Min(newW, NewH): Next CtrL.ColumnWidths = Join(tc, ";") End If On Error Resume Next CtrL.Font.Size = t(4) * Application.Min(newW, NewH) Err.Clear: On Error GoTo 0 Next End Sub
et maintenat le même exactement avec les api déclarées en bon et due forme
VB:'***************************************************************************************************** ' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _. ' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| // ' //___// //__\ // //__// // // //__// // // // // // // // // // | // ' // // \\ // // \\ // // // \\ // // // // // // // // // | // '// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |// '**************************************************************************************************** ' Module RESIZER userform version basic 'version avec api déclarées 'release 2020 for XLD '**************************************************************************************************** Option Explicit #If VBA7 Then #If Win64 Then Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _ ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #Else Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _ ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Public Declare PtrSafe Function ShowWindow Lib "user32" ( _ ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long Public Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr #Else 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 FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function ShowWindow Lib "user32" ( _ ByVal hWnd As Long, ByVal nCmdShow As Long) As Long Public Declare Function GetActiveWindow Lib "user32" () As Long #End If Dim OldW#, OldH# Sub trois_boutons() 'ajoute les 3 boutons et le resize dynamique à l'userform Dim hWnd& hWnd = GetActiveWindow SetWindowLongPtr hWnd, -16, &H94CF0080 'api SetWindowLongA End Sub Sub NoTitleBar() 'supprime la barre de titre( rempli absolument tout l'ecran Dim hWnd& hWnd = GetActiveWindow SetWindowLongPtr hWnd, -16, &H140F0101 End Sub Sub SameSizeApplication(usf) 'taille et position identique à l'application With Application usf.Move .Left, .Top, .Width, .Height End With End Sub Sub UsfFullScreen() 'met le userform en plein ecran Dim hWnd& hWnd = GetActiveWindow ShowWindow hWnd, 3 End Sub Sub memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension Dim CtrL OldW = usf.Width OldH = usf.Height For Each CtrL In usf.Controls CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height On Error Resume Next CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size CtrL.Tag = CtrL.Tag & ";" Err.Clear: On Error GoTo 0 If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|") End If CtrL.Tag = CtrL.Tag & ";" Next End Sub Sub resiZer(usf) Dim newW#, NewH#, t, cw$, tc, CtrL, i& newW = usf.Width / OldW NewH = usf.Height / OldH For Each CtrL In usf.Controls t = Split(CtrL.Tag, ";") CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then If CtrL.ColumnWidths = "" Then cw = Application.Rept("80", CtrL.ColumnCount) Else cw = CtrL.ColumnWidths tc = Split(t(6), "|") For i = 0 To UBound(tc): tc(i) = Val(tc(i)) * Application.Min(newW, NewH): Next CtrL.ColumnWidths = Join(tc, ";") End If On Error Resume Next CtrL.Font.Size = t(4) * Application.Min(newW, NewH) Err.Clear: On Error GoTo 0 Next End Sub
voila le resize est tout totomatic
vous pouvez tester avec ce classeur il y a 3 userform exemples
l'userform1 utilisera le module avec la methode par les macro4(plein ecran, les trois boutons dans la barre de titre et la taskbar est visible)
l'userform2 utilisera le module avec api déclarées(plein ecran, pas de barre de titre, pas de taskbar(il couvre absolument tout l'ecran)
l'userform3 utilisera le module api déclarées(couvre l'application ,pas de barre de titre )
un peu d'humour
@Nain porte quoi
non on ca plait au nazes
??? 😳Voilà, encore un qui pense avoir les poumons plus oxygénés que les autres.
Je te remercie pour ta magistrale démonstration.oui appelle appelle resizer1 a la place de resizer dans le userform1
Private Sub UserForm_Initialize()
'code pour userform2
memoControlSize Me
End Sub
Private Sub UserForm_Activate()
Static done As Boolean
If done Then Exit Sub
done = True
NoTitleBar
UsfFullScreen
End Sub
Private Sub UserForm_Resize()
resiZer Me
End Sub
Et si vous ouvriez une nouvelle discussion entre vous ?
'*****************************************************************************************************
' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _.
' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| //
' //___// //__\ // //__// // // //__// // // // // // // // // // | //
' // // \\ // // \\ // // // \\ // // // // // // // // // | //
'// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |//
'****************************************************************************************************
' Module RESIZER userform version basic
'version avec api déclarées
'release 2020 for XLD
'****************************************************************************************************
Option Explicit
#If VBA7 Then
#If Win64 Then
Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Public Declare PtrSafe Function ShowWindow Lib "user32" ( _
ByVal Hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Public Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
#Else
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 FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" ( _
ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
#End If
#If VBA7 Then
Dim Hwnd As LongPtr
#Else
Dim Hwnd As Long
#End If
Dim OldW#, OldH#
Sub trois_boutons() 'ajoute les 3 boutons et le resize dynamique à l'userform
Hwnd = GetActiveWindow
SetWindowLongPtr Hwnd, -16, &H94CF0080 'api SetWindowLongA
End Sub
Sub NoTitleBar() 'supprime la barre de titre( rempli absolument tout l'ecran
Hwnd = GetActiveWindow
SetWindowLongPtr Hwnd, -16, &H140F0101
End Sub
Sub SameSizeApplication(usf) 'taille et position identique à l'application
With Application
usf.Move .Left, .Top, .Width, .Height
End With
End Sub
Sub UsfFullScreen() 'met le userform en plein ecran
Hwnd = GetActiveWindow
ShowWindow Hwnd, 3
End Sub
Sub memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension
Dim CtrL
OldW = usf.Width
OldH = usf.Height
For Each CtrL In usf.Controls
CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height
On Error Resume Next
CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size
CtrL.Tag = CtrL.Tag & ";"
Err.Clear: On Error GoTo 0
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|")
End If
CtrL.Tag = CtrL.Tag & ";"
Next
End Sub
Sub resiZer(usf)
Dim newW#, NewH#, t, cw$, tc, CtrL, i&
newW = usf.Width / OldW
NewH = usf.Height / OldH
For Each CtrL In usf.Controls
t = Split(CtrL.Tag, ";")
CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
If CtrL.ColumnWidths = "" Then
cw = Application.Rept("80 ", CtrL.ColumnCount)
cw = Replace(Trim(cw), " ", " pt;")
t(6) = cw
'Else: cw = CtrL.ColumnWidths
End If
tc = Split(t(6), "|")
For i = 0 To UBound(tc): tc(i) = Val(tc(i)) * Application.Min(newW, NewH): Next
CtrL.ColumnWidths = Join(tc, " pt;")
'MsgBox CtrL.ColumnWidths
End If
On Error Resume Next
CtrL.Font.Size = t(4) * Application.Min(newW, NewH)
Err.Clear: On Error GoTo 0
Next
End Sub
Bon pour le columnwiths l'I.A a encore raconté des bêtises. J'ai pu essayé le code avec un excel 2010 : le problème c'est pas l'absence d'unités mais c'est que excel 2010 n'aime pas les décimales dans le columnwidths des ListBox. Avec ce code cela fonctionne avec un excel 2010 :re
@nullosse
oui tu a peut être raison les dim avec "&" pour long sont forcement faux pour le 64 par contre je suis étonné que le non typé donc variant fonctionne puisque les déclarations attendent un longptr en vba 7
pour ce cw(columnwidths) je n'avais jamais entendu parler de ça mais soit
voici donc le code corrigé en conséquence
VB:'***************************************************************************************************** ' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _. ' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| // ' //___// //__\ // //__// // // //__// // // // // // // // // // | // ' // // \\ // // \\ // // // \\ // // // // // // // // // | // '// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |// '**************************************************************************************************** ' Module RESIZER userform version basic 'version avec api déclarées 'release 2020 for XLD '**************************************************************************************************** Option Explicit #If VBA7 Then #If Win64 Then Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _ ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #Else Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _ ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Public Declare PtrSafe Function ShowWindow Lib "user32" ( _ ByVal Hwnd As LongPtr, ByVal nCmdShow As Long) As Long Public Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr #Else 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 FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function ShowWindow Lib "user32" ( _ ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long Public Declare Function GetActiveWindow Lib "user32" () As Long #End If #If VBA7 Then Dim Hwnd As LongPtr #Else Dim Hwnd As Long #End If Dim OldW#, OldH# Sub trois_boutons() 'ajoute les 3 boutons et le resize dynamique à l'userform Hwnd = GetActiveWindow SetWindowLongPtr Hwnd, -16, &H94CF0080 'api SetWindowLongA End Sub Sub NoTitleBar() 'supprime la barre de titre( rempli absolument tout l'ecran Hwnd = GetActiveWindow SetWindowLongPtr Hwnd, -16, &H140F0101 End Sub Sub SameSizeApplication(usf) 'taille et position identique à l'application With Application usf.Move .Left, .Top, .Width, .Height End With End Sub Sub UsfFullScreen() 'met le userform en plein ecran Hwnd = GetActiveWindow ShowWindow Hwnd, 3 End Sub Sub memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension Dim CtrL OldW = usf.Width OldH = usf.Height For Each CtrL In usf.Controls CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height On Error Resume Next CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size CtrL.Tag = CtrL.Tag & ";" Err.Clear: On Error GoTo 0 If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|") End If CtrL.Tag = CtrL.Tag & ";" Next End Sub Sub resiZer(usf) Dim newW#, NewH#, t, cw$, tc, CtrL, i& newW = usf.Width / OldW NewH = usf.Height / OldH For Each CtrL In usf.Controls t = Split(CtrL.Tag, ";") CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then If CtrL.ColumnWidths = "" Then cw = Application.Rept("80 ", CtrL.ColumnCount) cw = Replace(Trim(cw), " ", " pt;") t(6) = cw 'Else: cw = CtrL.ColumnWidths End If tc = Split(t(6), "|") For i = 0 To UBound(tc): tc(i) = Val(tc(i)) * Application.Min(newW, NewH): Next CtrL.ColumnWidths = Join(tc, " pt;") 'MsgBox CtrL.ColumnWidths End If On Error Resume Next CtrL.Font.Size = t(4) * Application.Min(newW, NewH) Err.Clear: On Error GoTo 0 Next End Sub
tc = Split(t(6), "|")
For i = 0 To UBound(tc): tc(i) = Int(Val(tc(i)) * Application.Min(newW, NewH)): Next
CtrL.ColumnWidths = Join(tc, ";")
Initialize
Activate
Resize (seulement si la taille change réellement)
Initialize
Resize (1 à plusieurs fois)
Activate
Et pour répondre au titre de la discussion :Par contre, l'UserForm n'est pas extensible. Je sais que j'ai mis un peu de baratin mais, pour certaines plantes (agrumes par ex.), il faut des tonnes de recommandations. Mais faire de la place à ce Label sans toucher à la taille de l'UserForm me semble compliqué.
😉On les plante avec le doigt
À la mode, à la mode
On les plante avec le doigt
À la mode de chez nous.
Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
NoTitleBar
memoControlSize Me
Dim t
t = Timer
Do While Timer - t < 1: DoEvents: Loop
UsfFullScreen
End Sub
Private Sub UserForm_Resize()
resiZer Me
End Sub
Salut patricktoulon,je ne suis pas sur de ce que tu dis @nullosse
Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
NoTitleBar
' memoControlSize Me
UsfFullScreen1
End Sub
Private Sub UserForm_Initialize()
memoControlSize Me
End Sub
Private Sub UserForm_Resize()
resiZer Me
End Sub
Là dessus, plusieurs membres continuent à échanger des messages qui n'ont aucun rapport avec mon questionnement initial.
Résultat : tout le monde s'énerve, nain porte quoi devient grossier et je souhaite que ce cirque arrête.
D'où ma proposition d'ouvrir une nouvelle discussion entre vous. Rien de plus...
'*****************************************************************************************************
' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _.
' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| //
' //___// //__\ // //__// // // //__// // // // // // // // // // | //
' // // \\ // // \\ // // // \\ // // // // // // // // // | //
'// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |//
'****************************************************************************************************
' Module RESIZER userform version basic
'version avec api déclarées
'release 2020 for XLD
'****************************************************************************************************
Option Explicit
#If VBA7 Then
#If Win64 Then
Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _
ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Public Declare PtrSafe Function ShowWindow Lib "user32" ( _
ByVal Hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Dim Hwnd As LongPtr
#Else
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 FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" ( _
ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long
Dim Hwnd As Long
#End If
Public OldW As Double
Public OldH As Double
Sub trois_boutons(usf) 'ajoute les 3 boutons et le resize dynamique à l'userform
Hwnd = FindWindow(vbNullString, usf.Caption)
SetWindowLongPtr Hwnd, -16, &H94CF0080 'api SetWindowLongA
End Sub
Sub NoTitleBar(usf) 'supprime la barre de titre( rempli absolument tout l'ecran
Hwnd = FindWindow(vbNullString, usf.Caption)
SetWindowLongPtr Hwnd, -16, &H140F0101
End Sub
Sub SameSizeApplication(usf) 'taille et position identique à l'application
With Application
usf.Move .Left, .Top, .Width, .Height
End With
End Sub
Sub UsfFullScreen(usf) 'met le userform en plein ecran
Hwnd = FindWindow(vbNullString, usf.Caption)
ShowWindow Hwnd, 3
End Sub
Function memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension
Dim CtrL
OldW = usf.Width
OldH = usf.Height
For Each CtrL In usf.Controls
CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height
On Error Resume Next
CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size
CtrL.Tag = CtrL.Tag & ";"
Err.Clear: On Error GoTo 0
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|")
End If
CtrL.Tag = CtrL.Tag & ";"
DoEvents
Next
memoControlSize = OldW > 0
End Function
Sub resiZer(usf)
Dim newW#, NewH#, t, cw$, tc, CtrL, i&
Do While OldW = 0: DoEvents: Loop
newW = usf.Width / OldW
NewH = usf.Height / OldH
For Each CtrL In usf.Controls
t = Split(CtrL.Tag, ";")
CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
If CtrL.ColumnWidths = "" Then
cw = Application.Rept("80 ", CtrL.ColumnCount)
cw = Replace(cw, " ", "|")
t(6) = cw
'Else: cw = CtrL.ColumnWidths
End If
tc = Split(t(6), "|")
For i = 0 To UBound(tc): tc(i) = Int(Val(tc(i)) * Application.Min(newW, NewH)): Next
CtrL.ColumnWidths = Join(tc, " pt;")
'MsgBox CtrL.ColumnWidths
End If
On Error Resume Next
CtrL.Font.Size = t(4) * Application.Min(newW, NewH)
Err.Clear: On Error GoTo 0
Next
End Sub
Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
ListBox1.List = [A1:B10].Value
ListBox2.List = [A1:A10].Value
NoTitleBar Me
If memoControlSize(Me) Then
UsfFullScreen Me
Else
MsgBox "Il c'est produit un problème lors de la memorisation des positions et dimensions des controls"
End If
End Sub
Private Sub UserForm_Resize()
resiZer Me
End Sub
Fonctionne chez toi sur une machine virtuelle.bon apres diverses recherches et tests
c'est bel et bien un problème de timming pour office 2010
du coup j'ai revu le truc
1 la mémorisation devient une fonction et donc retourne une valeur
ça permet a vba de s'arrêter tant que le return n'est pas effectif contrairement a une subj'ai même mis une gestion d'attente dans le resizer
2 effectivement vu que le timing est non syncro getactivewindow peut renvoyer le handle de l'application
du coup on passe par findwindow qui permet de capter le handle même si la fenêtre n'est pas complétement affichéalors effectivement on pourrait mettre le memo dans le initialise pour avoir encore plus de tempstesté sur 2010 en virtual machine donc sans parasiteVB:'***************************************************************************************************** ' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _. ' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| // ' //___// //__\ // //__// // // //__// // // // // // // // // // | // ' // // \\ // // \\ // // // \\ // // // // // // // // // | // '// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |// '**************************************************************************************************** ' Module RESIZER userform version basic 'version avec api déclarées 'release 2020 for XLD '**************************************************************************************************** Option Explicit #If VBA7 Then #If Win64 Then Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _ ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #Else Public Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _ ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Public Declare PtrSafe Function ShowWindow Lib "user32" ( _ ByVal Hwnd As LongPtr, ByVal nCmdShow As Long) As Long Dim Hwnd As LongPtr #Else 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 FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function ShowWindow Lib "user32" ( _ ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long Dim Hwnd As Long #End If Public OldW As Double Public OldH As Double Sub trois_boutons(usf) 'ajoute les 3 boutons et le resize dynamique à l'userform Hwnd = FindWindow(vbNullString, usf.Caption) SetWindowLongPtr Hwnd, -16, &H94CF0080 'api SetWindowLongA End Sub Sub NoTitleBar(usf) 'supprime la barre de titre( rempli absolument tout l'ecran Hwnd = FindWindow(vbNullString, usf.Caption) SetWindowLongPtr Hwnd, -16, &H140F0101 End Sub Sub SameSizeApplication(usf) 'taille et position identique à l'application With Application usf.Move .Left, .Top, .Width, .Height End With End Sub Sub UsfFullScreen(usf) 'met le userform en plein ecran Hwnd = FindWindow(vbNullString, usf.Caption) ShowWindow Hwnd, 3 End Sub Function memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension Dim CtrL OldW = usf.Width OldH = usf.Height For Each CtrL In usf.Controls CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height On Error Resume Next CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size CtrL.Tag = CtrL.Tag & ";" Err.Clear: On Error GoTo 0 If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|") End If CtrL.Tag = CtrL.Tag & ";" DoEvents Next memoControlSize = OldW > 0 End Function Sub resiZer(usf) Dim newW#, NewH#, t, cw$, tc, CtrL, i& Do While OldW = 0: DoEvents: Loop newW = usf.Width / OldW NewH = usf.Height / OldH For Each CtrL In usf.Controls t = Split(CtrL.Tag, ";") CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then If CtrL.ColumnWidths = "" Then cw = Application.Rept("80 ", CtrL.ColumnCount) cw = Replace(cw, " ", "|") t(6) = cw 'Else: cw = CtrL.ColumnWidths End If tc = Split(t(6), "|") For i = 0 To UBound(tc): tc(i) = Int(Val(tc(i)) * Application.Min(newW, NewH)): Next CtrL.ColumnWidths = Join(tc, " pt;") 'MsgBox CtrL.ColumnWidths End If On Error Resume Next CtrL.Font.Size = t(4) * Application.Min(newW, NewH) Err.Clear: On Error GoTo 0 Next End Sub
dans le userform
finalement c'est grâce a @cathodique que j'ai compris le trucVB:Option Explicit Private Sub CommandButton1_Click() Unload Me End Sub Private Sub UserForm_Activate() ListBox1.List = [A1:B10].Value ListBox2.List = [A1:A10].Value NoTitleBar Me If memoControlSize(Me) Then UsfFullScreen Me Else MsgBox "Il c'est produit un problème lors de la memorisation des positions et dimensions des controls" End If End Sub Private Sub UserForm_Resize() resiZer Me End Sub
j'aurais du même comprendre a la lecture du code fantasmagorique de chatGpt
normalment a gestion d'attente suffisante ca devrait coller pour tout le monde
Patrick
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?