Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

XL 2013 Modifier mon code

maval

XLDnaute Barbatruc
Bonjour,

Jai un formulaire avec des frames que je rend visible ou non à l'aide d"OptionButton

et j'aimerai avoir mon code plus court et mieux construit
Mon Code :
VB:
Private Sub UserForm_Initialize()
Frame1.Visible = True
Frame2.Visible = False
Me.Width = 579
Me.Height = 125
End Sub

Private Sub CommandButton1_Click()
Frame1.Visible = True
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Me.Width = 579
Me.Height = 125
Frame1.Top = 18
End Sub

Private Sub CommandButton2_Click()
Frame1.Visible = True
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Me.Width = 579
Me.Height = 125
Frame1.Top = 18
End Sub

Private Sub CommandButton3_Click()
Frame1.Visible = True
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Me.Width = 579
Me.Height = 125
Frame1.Top = 18
End Sub

Private Sub OptionButton1_Click()
Frame1.Visible = False
Frame2.Visible = True
Frame3.Visible = False
Frame4.Visible = False
Frame2.Top = 18
Me.Width = 579
Me.Height = 205
OptionButton1.Value = False
End Sub

Private Sub OptionButton2_Click()
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = True
Frame4.Visible = False
Frame3.Top = 18
Me.Width = 579
Me.Height = 240
OptionButton2.Value = False
End Sub

Private Sub OptionButton3_Click()
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = True
Frame4.Top = 18
Me.Width = 579
Me.Height = 280
OptionButton3.Value = False
End Sub


Je joint mon formulaire qui seras plus explicite.
 

Pièces jointes

  • Frame.xlsm
    29.9 KB · Affichages: 12

mapomme

XLDnaute Barbatruc
Supporter XLD
Bonjour @maval , @ChTi160 ,

Voilà du condensé :
Code:
Private Sub OptionButton1_Click(): AfficherFrame 2: End Sub
Private Sub OptionButton2_Click(): AfficherFrame 3: End Sub
Private Sub OptionButton3_Click(): AfficherFrame 4: End Sub
Private Sub CommandButton1_Click(): AfficherFrame 1: End Sub
Private Sub CommandButton2_Click(): AfficherFrame 1: End Sub
Private Sub CommandButton3_Click(): AfficherFrame 1: End Sub
Private Sub UserForm_Initialize(): AfficherFrame 1: End Sub
Sub AfficherFrame(xNum&)
Dim i&
  For i = 1 To 4: Controls("Frame" & i).Visible = False: Next
  Controls("Frame" & xNum).Visible = True: Controls("Frame" & xNum).Top = 18
  Me.Width = 579: Me.Height = 18 + Controls("Frame" & xNum).Height + 30
End Sub
 

Pièces jointes

  • maval- Frame- v1.xlsm
    20.2 KB · Affichages: 11

mapomme

XLDnaute Barbatruc
Supporter XLD
Re @maval ,

Si tu veux que les boutons options soient tous décochés quand on affiche Frame1, on peux ajouter une ligne à la procédure AfficherFrame, ce qui donne:
VB:
Sub AfficherFrame(xNum&)
Dim i&
  For i = 1 To 3: Controls("OptionButton" & i) = False: Next
  For i = 1 To 4: Controls("Frame" & i).Visible = False: Next
  Controls("Frame" & xNum).Visible = True: Controls("Frame" & xNum).Top = 18
  Me.Width = 579: Me.Height = 18 + Controls("Frame" & xNum).Height + 30
End Sub
 

Discussions similaires

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…