macro a corriger svp

  • Initiateur de la discussion Initiateur de la discussion hicham28
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

hicham28

XLDnaute Occasionnel
Bonsoir, et merci d'avance, j'aimerai savoir si il y'as une autre méthode exécuter rapidement du code ci joint, merci encore
Code:
Private Sub Workbook_Open()
ActiveWindow.Zoom = 113
      
    Range("A18:A65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With
Range("B18:B65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 10
   End With
Range("C18:C65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 18
   End With
Range("D18:D65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 11
   End With
Range("E18:E65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 11
   End With
Range("F18:F65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 11
   End With
Range("G18:G65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 11
   End With
Range("H18:H65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 6
   End With
Range("I18:I65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 6
   End With
Range("J18:J65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With

Range("K18:K65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With

Range("L18:L65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With
Range("M18:M65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 6
   End With

Range("N18:N65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With

Range("O18:O65536").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
        .ColumnWidth = 9
   End With
End Sub
 
Re : macro a corriger svp

Bonsoir Hicham, bonsoir le forum,

Peut-être comme ça :
Code:
Private Sub Workbook_Open()
Dim x As Byte
ActiveWindow.Zoom = 113
 
With Sheets("Feuil1") 'à adapter à ton cas
    With .Range("A18:O65536")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
 
    For x = 1 To 15
        Select Case x
            Case 1, 10, 11, 12, 14, 15
                .Columns(x).ColumnWidth = 9
            Case 2
                .Columns(x).ColumnWidth = 10
            Case 3
                .Columns(x).ColumnWidth = 18
            Case 4 To 7
                .Columns(x).ColumnWidth = 11
            Case 8, 9, 13
                .Columns(x).ColumnWidth = 6
        End Select
    Next x
End With
End Sub
 
Re : macro a corriger svp

Bonsoir hicham28
Essayez ceci :
Code:
[COLOR="DarkSlateGray"][B]Private Sub Workbook_Open()
   ActiveWindow.Zoom = 113
   With Range("A18:O65536")
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlTop
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .ShrinkToFit = False
      .MergeCells = False
   End With
   Columns("A:A,J:L,N:O").ColumnWidth = 9
   Columns("B:B").ColumnWidth = 10
   Columns("C:C").ColumnWidth = 18
   Columns("D:G").ColumnWidth = 11
   Columns("H:I,M:M").ColumnWidth = 6
End Sub[/B][/COLOR]
ROGER2327
#3483


26 Floréal An CCXVIII
2010-W19-6T21:41:22Z


_______________
Bonsoir Robert.
 
Re : macro a corriger svp

en faite j'ai aussi plusieurs feuils et j'aimerai gerer aussi leurs zome, j'arrive pas a le faire avec ce code, ou est l'erreur??? merci
Code:
Private Sub Workbook_Open()
Dim x As Byte
 
With Sheets("FACTURE") 'à adapter à ton cas
  ActiveWindow.Zoom = 113
   With .Range("A18:O65536")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
 
    For x = 1 To 15
        Select Case x
            Case 1, 10, 11, 12, 14, 15
                .Columns(x).ColumnWidth = 9
            Case 2
                .Columns(x).ColumnWidth = 10
            Case 3
                .Columns(x).ColumnWidth = 18
            Case 4 To 7
                .Columns(x).ColumnWidth = 11
            Case 8, 9, 13
                .Columns(x).ColumnWidth = 6
        End Select
    Next x
End With
With Sheets("PORTEFEUILLE") 'à adapter à ton cas
    ActiveWindow.Zoom = 100
    With .Range("A6:H65536")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
 
    For x = 1 To 8
        Select Case x
            Case 1
                .Columns(x).ColumnWidth = 16
            Case 2, 4, 5, 6
                .Columns(x).ColumnWidth = 12
            Case 3
                .Columns(x).ColumnWidth = 8
            Case 7
                .Columns(x).ColumnWidth = 20
            Case 8
                .Columns(x).ColumnWidth = 10
        End Select
    Next x
End With

End Sub
 
Re : macro a corriger svp

Bonsoir le fil, bonsoir le forum,

J'avais mal lu pardon... je re regarde...
Le zoom se fait par rapport à la fenêtre active. Dans WorkBook_Open tu n'actives aucun onglet... Essaie plutôt comme ça :
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "FACTURE" Then ActiveWindow.Zoom = 113
If Sh.Name = "PORTEFEUILLE" Then ActiveWindow.Zoom = 100
End Sub
 
Dernière édition:
Re : macro a corriger svp

vous n'avez pas a etre dsl, c'est ma faute, j'ai mal exposer le sujet, et merci de ton aide, j'aimerai bien savoir si il y'as pas un autre moyen pour que les zomes soient gerer a l'ouverture et aussi a l'activiation des feuilles?? merci
 
Dernière édition:
Re : macro a corriger svp

Bonjour Hicham, Robert (qui est Zahia?)

Une autre façon d'écrire la macro de Robert

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
On Error Resume Next
ActiveWindow.Zoom = _
CLng(Switch(Sh.Name = "FACTURE", 113, Sh.Name = "PORTEFEUILLE", 100))
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
1 K
Réponses
7
Affichages
327
  • Question Question
Microsoft 365 Export données
Réponses
4
Affichages
863
Réponses
11
Affichages
919
Réponses
2
Affichages
567
Retour