Redimensionner un Userform
Bonjour le fofo,
Voilà en cherchant à droite à gauche j'ai adapté un code pour redimensionner un Userform lors de son lancement:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long '
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Function ResizeUserForm(UForm As Object)
Dim hwnd As Long, exlong As Long, factor As Integer, zfactor As Integer
Dim UCaption As String
UCaption = UForm.Caption
hwnd = FindWindowA(vbNullString, UCaption)
exlong = GetWindowLong(hwnd, -16)
zfactor = 1000 * (Application.Width / (UForm.Width + 20))
factor = 1000 * (Application.Height / (UForm.Height + 20))
If factor < 1000 Then
PrAc = CInt(((1000 - factor) / factor) * 100 + 1)
Zoom = 100 + PrAc
UForm.Width = UForm.Width / (Zoom / 100)
UForm.Height = UForm.Height / (Zoom / 100)
If PrAc > 5 Then
UForm.Zoom = 200 - (Zoom - 5)
Else
UForm.Zoom = 200 - Zoom
End If
End If
If zfactor < 1000 Then
'rien pour l'instant
End If
End Function |
Seul soucis, le code s'applique selon la taille de la fenêtre de l'application Excel et non celle de la résolution de l'écran.
Quelqu'un aurait une idée?
Merci
Redimensionner un Userform
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Option Explicit
Private Declare Function FindWindowA Lib "User32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLongA Lib "User32" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLongA Lib "User32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Sub UserForm_Initialize()
Dim hWnd As Long, exLong As Long, zFactor As Integer
hWnd = FindWindowA(vbNullString, Me.Caption)
exLong = GetWindowLongA(hWnd, -16)
If exLong And &H880000 Then SetWindowLongA hWnd, -16, exLong And &HFF77FFFF
zFactor = 100 * CInt(Application.Width / Me.Width)
Me.Width = Application.Width
Me.Height = Application.Height
End Sub |