Option Explicit
#If Win64 Then
Declare PtrSafe Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
#Else
Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
#End If
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub RedimLargFenetreAPI()
Dim Pl As Range
Dim hwnd As Long
Dim Zone As RECT
Dim LargAscenseur As Long
Dim BordFeuille As Long
'on récupère le pixel du bord gauche de la fenêtre Microsoft Excel
hwnd = Application.hwnd
GetWindowRect hwnd, Zone
BordFeuille = Zone.Left
'on récupère le Handle de l'ascenseur vertical
hwnd = FindWindowEx(hwnd, ByVal 0&, "XLDESK", vbNullString)
hwnd = FindWindowEx(hwnd, ByVal 0&, "EXCEL7", vbNullString)
hwnd = FindWindowEx(hwnd, ByVal 0&, "NUIScrollbar", vbNullString)
'on récupère la largeur en pixels de l'ascenseur vertical
GetClientRect hwnd, Zone
LargAscenseur = Zone.Right
Set Pl = [A1].CurrentRegion
With ActiveWindow
.WindowState = xlNormal
.Top = 1
.Left = 1
.Height = Application.UsableHeight
'on convertit la largeur de la plage en pixels + largeur de l'ascenseur + contour de la fenêtre Excel
.Width = ActiveWindow.PointsToScreenPixelsX(Pl.Width) + LargAscenseur + BordFeuille
End With
End Sub