Les retours de @RyuAutodidacte ne sont pas très clairs dans la conversation privée qu'on a eu sur le sujet concernant Application.UsableWidth et Application.UsableHeight.avec application .width et application .height quand excel est maximisé te renvoie les dim en pixels
testé par notre ami ryu qui a confirmé mes soupçons
Sub a()
MsgBox ActiveWindow.Width & " x " & ActiveWindow.Height & vbCrLf & _
Application.Width & " x " & Application.Height & vbCrLf & _
Application.UsableWidth & " x " & Application.UsableHeight & vbCrLf & _
ActiveWindow.UsableWidth & " x " & ActiveWindow.UsableHeight
End Sub
'https://learn.microsoft.com/fr-fr/office/vba/api/excel.application.usablewidth
'This example expands the active window to the maximum size available (assuming that the window isn't already maximized).
'=> NE FONCTIONNE PAS !
Sub b()
With ActiveWindow
.WindowState = xlNormal
.Top = 1
.Left = 1
.Height = Application.UsableHeight
.Width = Application.UsableWidth
End With
End Sub
Là tu fixes des points arbitrairement mais ils peuvent ne pas correspondre à la réalité car par exemple, on peut avoir plusieurs moniteurs en position négative ou positive.toi qui a deux écrans que donne
Eg=MonitorFromPoint(-10000, 1, &H2)
Ed= MonitorFromPoint(10000, 1, &H2)
Function GetMonitorMIs() As MONITORINFO()
Dim TabMIs() As MONITORINFO
Dim NbMIs As Integer
Dim hMonitor As LongPtr
Dim MI As MONITORINFO
Dim Point As POINTAPI
Dim PreviousLeft As Long
'Look for monitors on the right of the primary monitor
Point.X = 0
Point.Y = 0
PreviousLeft = -1
Do While 1
hMonitor = MonitorFromPoint(Point, 2)
MI.cbSize = Len(MI)
Call GetMonitorInfo(hMonitor, MI)
If MI.rcMonitor.Left = PreviousLeft Then Exit Do
NbMIs = NbMIs + 1
ReDim Preserve TabMIs(1 To NbMIs)
TabMIs(NbMIs) = MI
PreviousLeft = MI.rcMonitor.Left
Point.X = Point.X + MI.rcMonitor.Right
Loop
'Look for monitors on the left of the primary monitor
Point.X = 0
Point.Y = 0
PreviousLeft = 1
Do While 1
hMonitor = MonitorFromPoint(Point, 2)
MI.cbSize = Len(MI)
Call GetMonitorInfo(hMonitor, MI)
If MI.rcMonitor.Left = PreviousLeft Then Exit Do
If Not Point.X = 0 Then
NbMIs = NbMIs + 1
ReDim Preserve TabMIs(1 To NbMIs)
TabMIs(NbMIs) = MI
End If
PreviousLeft = MI.rcMonitor.Left
Point.X = Point.X + MI.rcMonitor.Left - 1
Loop
'Return value
GetMonitorMIs = TabMIs
End Function
Très bonne idée.Pourquoi tu n'utilises pas la propriété du Userform ?
Sub a()
Dim S As String
S = "WindowState = "
Select Case Application.WindowState
Case xlMaximized
S = S & "xlMaximized"
Case xlMinimized
S = S & "xlMinimized"
Case xlNormal
S = S & "xlNormal"
Case Else
S = S & "Inconnu"
End Select
S = S & vbCrLf & vbCrLf & _
"ActiveWindow:" & vbCrLf
With ActiveWindow
S = S & _
"Left: " & .Left & ", Top: " & .Top & ", Width: " & .Width & ", Height: " & .Height & vbCrLf & _
"UsableWidth: " & .UsableWidth & ", UsableHeight: " & .UsableHeight
End With
S = S & vbCrLf & vbCrLf & _
"Application:" & vbCrLf
With Application
S = S & _
"Left: " & .Left & ", Top: " & .Top & ", Width: " & .Width & ", Height: " & .Height & vbCrLf & _
"UsableWidth: " & .UsableWidth & ", UsableHeight: " & .UsableHeight
End With
MsgBox S
End Sub
Je ne m'en doutais pas mais c'est exact. StartupPosition = 2 adresse l'écran principal !!!utiliser le startupposition du userform n'est pas bonne non plus
puisque il s'affichera sur l’écran dit(principal)