Autres Positionner mon userform en haut de l'écran

fenec

XLDnaute Impliqué
Bonjour le forum,
Comme le dit le titre je viens vers vous car je souhaiterais que mon userform se positionne en haut de l’écran et si possible sans bandeau.
Est ce possible?
Cordialement ,
Philippe.
 

Pièces jointes

  • essai userform.xls
    126 KB · Affichages: 13

patricktoulon

XLDnaute Barbatruc
c'est cela que tu veux
VB:
Option Explicit
Dim oldx, oldy
Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Activate()
    Dim ex#, ey#
    With Me
        oldx = .Width
        oldy = .Height
        For Each ctrl In Me.Controls
            ctrl.Tag = Join(Array(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height), ";")
            On Error Resume Next
            ctrl.Tag = ctrl.Tag & ";" & ctrl.Font.Size
            Err.Clear
        Next
        ex = .Width - .InsideWidth
        ey = .Height - .InsideHeight
        .Top = -ey
        .Left = -ex
        .Width = Application.Width - ex
    End With
End Sub


Private Sub UserForm_Resize()
    Dim Dimo, i&, ctrl, newlarge, newh
    On Error Resume Next
    i = 0
    For Each ctrl In Controls
        Dimo = Split(ctrl.Tag, ";")
        newlarge = Me.Width / oldx: newh = Me.Height / oldy
        ctrl.Move Dimo(0) * newlarge, Dimo(1) * newh, Dimo(2) * newlarge
        'ctrl.FontSize =
    Next
End Sub
 

patricktoulon

XLDnaute Barbatruc
c'est cela que tu veux
1598204523567.png

vire tout ce qui y a dans l'userform
VB:
Option Explicit
Dim oldx, oldy
Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Activate()
    Dim ex#, ey#
    With Me
        oldx = .Width
        oldy = .Height
        For Each ctrl In Me.Controls
            ctrl.Tag = Join(Array(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height), ";")
            On Error Resume Next
            ctrl.Tag = ctrl.Tag & ";" & ctrl.Font.Size
            Err.Clear
        Next
        ex = .Width - .InsideWidth
        ey = .Height - .InsideHeight
        .Top = -ey
        .Left = -ex
        .Width = Application.Width - ex
    End With
End Sub


Private Sub UserForm_Resize()
    Dim Dimo, i&, ctrl, newlarge, newh
    On Error Resume Next
    i = 0
    For Each ctrl In Controls
        Dimo = Split(ctrl.Tag, ";")
        newlarge = Me.Width / oldx: newh = Me.Height / oldy
        ctrl.Move Dimo(0) * newlarge, Dimo(1) * newh, Dimo(2) * newlarge
        'ctrl.FontSize =
    Next
End Sub
 

fenec

XLDnaute Impliqué
C’est tout a fait ca que je voulais en plus il est fixe pour que les utilisateurs du fichier ne puisse faire des bétises en se servant du bandeau d’excel mais comment procédé pour que je puisse avoir la main si besoin de modifier quelque chose ?
 

patricktoulon

XLDnaute Barbatruc
re
tiens voila
tu veux remettre le ruban et fermer l'userform
ben tu clique sur fermer ca fait rien
et tu tape les touches CTRL+ENTER
A LA FERMETURE LE RUBAN SE REMET EN PLACE
VB:
Option Explicit
Dim oldx, oldy
Dim codekey
Dim counter
Private Sub CommandButton1_Click()
    'Unload Me
End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
counter = counter + 1
codekey = codekey + KeyCode
If codekey = 30 Then Unload Me Else If counter = 2 Then counter = 0: codekey = 0
End Sub

Private Sub UserForm_Activate()
    Dim ex#, ey#, ptopx
    With Me
        oldx = .Width
        oldy = .Height
        For Each ctrl In Me.Controls
            ctrl.Tag = Join(Array(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height), ";")
            On Error Resume Next
            ctrl.Tag = ctrl.Tag & ";" & ctrl.Font.Size
            Err.Clear
        Next
        ex = .Width - .InsideWidth
        ey = .Height - .InsideHeight
        .Top = -ey
        .Left = -ex
        .Width = Application.Width - ex
        ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"  'voila comment on vire le ruban
    End With
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",true)"  'voila comment on remet le ruban
End Sub

Private Sub UserForm_Resize()
    Dim Dimo, i&, ctrl, newlarge, newh
    i = 0
    For Each ctrl In Controls
        Dimo = Split(ctrl.Tag, ";")
        newlarge = Me.Width / oldx: newh = Me.Height / oldy
        ctrl.Move Dimo(0) * newlarge, Dimo(1) * newh, Dimo(2) * newlarge, Dimo(3) * newh
    Next
End Sub
 

patricktoulon

XLDnaute Barbatruc
une autre facon cette fois ci au clic sur bouton rouge mais le clic marche uniquement si la touche ctrl est enfoncée
la touche ctrl peu être remplacée par celle que tu décide il suffit de remplacer son keycode dans le code
bref des façons il y a a foison
VB:
Option Explicit
Dim oldx, oldy
Dim codekey
Dim counter
Private Sub CommandButton1_Click()
    If codekey = 17 Then Unload Me
End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'counter = counter + 1
'codekey = codekey + KeyCode
'If codekey = 30 Then Unload Me Else If counter = 2 Then counter = 0: codekey = 0
codekey = KeyCode
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
codekey = 0
End Sub

Private Sub UserForm_Activate()
    Dim ex#, ey#, ptopx
    With Me
        oldx = .Width
        oldy = .Height
        For Each ctrl In Me.Controls
            ctrl.Tag = Join(Array(ctrl.Left, ctrl.Top, ctrl.Width, ctrl.Height), ";")
            On Error Resume Next
            ctrl.Tag = ctrl.Tag & ";" & ctrl.Font.Size
            Err.Clear
        Next
        ex = .Width - .InsideWidth
        ey = .Height - .InsideHeight
        .Top = -ey
        .Left = -ex
        .Width = Application.Width - ex
        ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"  'voila comment on vire le ruban
    End With
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",true)"  'voila comment on remet le ruban
End Sub

Private Sub UserForm_Resize()
    Dim Dimo, i&, ctrl, newlarge, newh
    i = 0
    For Each ctrl In Controls
        Dimo = Split(ctrl.Tag, ";")
        newlarge = Me.Width / oldx: newh = Me.Height / oldy
        ctrl.Move Dimo(0) * newlarge, Dimo(1) * newh, Dimo(2) * newlarge, Dimo(3) * newh
    Next
End Sub
allez bonne soirée
a+ ;)
 

fenec

XLDnaute Impliqué
Bonjour le forum, Patricktoulon
je viens de tester tes deux dernières solutions c'est magnifique
Une préférence cependant pour le poste 24
Me reste à l'appliquer dans mon fichier final et surtout comprendre le code en commencant par comprendre les variables abrégées et les dièses et me permet de revenir en cas de problème
encore merci
 

Statistiques des forums

Discussions
312 228
Messages
2 086 421
Membres
103 205
dernier inscrit
zch