IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

ActiveSheet.Protect VBA ne fonctionne plus sous XL2010 [XL-2010]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2005
    Messages : 218
    Par défaut ActiveSheet.Protect VBA ne fonctionne plus sous XL2010
    Bonjour

    J'ai un code qui ne passe plus depuis mon passage sous Excel2010.
    Le verrouillage fonctionne, le déverrouillage aussi mais lorsque je verrouille de nouveau j'ai une erreur :


    Je ne vois pas où cela plante.

    Pourriez-vous m'aider ?

    Merci


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    Sub verrouiller()
    On Error GoTo 1:
    ActiveSheet.ShowAllData
    1:
    Range("L:L,O:O").Select
    Selection.Copy
     
    Columns("IU:IU").Select
    ActiveSheet.Paste
     
    Columns("IU:IU").Replace What:=".", Replacement:=".", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False
    Range("L1").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,C[243])"
    Range("K1").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection = "Sous Total"
    Columns("IV:IV").Replace What:=".", Replacement:=".", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False
    Range("O1").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,C[241])"
     
     
    Range("N1").Select
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Selection = "Sous Total"
     
     
    Cells.Select
    Selection.AutoFilter
     
    If ActiveSheet.AutoFilterMode Then
    Else
    Selection.AutoFilter
    End If
     
     
     
    Selection.AutoFilter Field:=15, Criteria1:="<>"
     
    Rows("1:1").Select
    With Selection.Interior
    .ColorIndex = 36
    .Pattern = xlSolid
    End With
     
     
    Columns("B:B").Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    Range("B1").Select
    ActiveSheet.Protect Password:="PASSWORD", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
    MsgBox "Le fichier 'outgoing invoice' est Vérouillé", vbInformation, "Confirmation"
     
    End Sub
     
     
    Sub dévérouiller()
    ActiveSheet.Unprotect Password:="PASSWORD"
     
    On Error GoTo fin:
    ActiveSheet.ShowAllData
    fin:
     
    Rows("65536:65536").Select
    Selection.ClearContents
    Columns("IU:IV").Select
    Selection.ClearContents
     
    Rows("1:1").Select
    With Selection.Interior
    .ColorIndex = 35
    .Pattern = xlSolid
    End With
    Columns("B:B").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
     
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "INVOICE_NR"
     
    MsgBox "Le fichier 'outgoing invoice' est Dévérouillé", vbInformation, "Confirmation"
    End Sub

  2. #2
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Bonjour
    Déjà tu travailles avec toutes les cellules, alors que tu n'en a pas besoin
    Évite en plus les Select

    To code aurait l'allure comme ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    Sub Verrouiller()
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    With ActiveSheet
        If .FilterMode Then .ShowAllData
        With .UsedRange
            .Range("L:L,O:O").Copy Range("IU1")
            .Range("IU:IV").Replace What:=".", Replacement:="."
            With .Cells(ActiveSheet.Rows.Count, "L").End(xlUp)
                .FormulaR1C1 = "=SUBTOTAL(9,C[243])"
                .Offset(0, -1) = "Sous Total"
            End With
            With .Cells(ActiveSheet.Rows.Count, "O").End(xlUp)
                .FormulaR1C1 = "=SUBTOTAL(9,C[241])"
                .Offset(0, -1) = "Sous Total"
            End With
            .AutoFilter Field:=15, Criteria1:="<>"
            .Rows("1:1").Interior.ColorIndex = 36
            With .Range("B:B")
                .Locked = False
                .FormulaHidden = False
            End With
        End With
        .Protect Userinterfaceonly:=True ',Password:="PASSWORD"
        .EnableSelection = xlUnlockedCells
    End With
    MsgBox "Le fichier 'outgoing invoice' est Vérouillé", vbInformation, "Confirmation"
    Application.Calculation = xlCalculationAutomatic
    End Sub

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2005
    Messages : 218
    Par défaut
    C'est beaucoup mieux oui

    Mais mon sous-total ne se met pas en dernière ligne mais dans le tableau (je joins le fichier)

    Et pour déverrouiller ?
    Fichiers attachés Fichiers attachés

  4. #4
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    En effet, Change comme ceci (lignes 10 et 14)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    Sub Verrouiller()
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    With ActiveSheet
        .Unprotect Password:="PASSWORD"
        If .FilterMode Then .ShowAllData
        With .UsedRange
            .Range("L:L,O:O").Copy Range("IU1")
            .Range("IU:IV").Replace What:=".", Replacement:=".", LookAt:=xlPart
            With .Cells(ActiveSheet.Rows.Count, "L").End(xlUp)(2)
                .FormulaR1C1 = "=SUBTOTAL(9,C[243])"
                .Offset(0, -1) = "Sous Total"
            End With
            With .Cells(ActiveSheet.Rows.Count, "O").End(xlUp)(2)
                .FormulaR1C1 = "=SUBTOTAL(9,C[241])"
                .Offset(0, -1) = "Sous Total"
            End With
            .AutoFilter Field:=15, Criteria1:="<>"
            .Rows("1:1").Interior.ColorIndex = 36
            With .Range("B:B")
                .Locked = False
                .FormulaHidden = False
            End With
        End With
        .Protect Userinterfaceonly:=True, Password:="PASSWORD"
        .EnableSelection = xlUnlockedCells
    End With
    MsgBox "Le fichier 'outgoing invoice' est Vérouillé", vbInformation, "Confirmation"
    Application.Calculation = xlCalculationAutomatic
    End Sub
    PS:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    .Protect Userinterfaceonly:=True, Password:="PASSWORD
    Permet de protéger la feuille en laissant les modifications par macro.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    218
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2005
    Messages : 218
    Par défaut
    Génial

    Et pour déverrouiller ?

  6. #6
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Bah qui sait conduire une R4, saura conduire une R12
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    Sub Dévérouiller()
     
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    With ActiveSheet
        .Unprotect Password:="PASSWORD"
        If .FilterMode Then .ShowAllData
        With .UsedRange
            .Rows(.Rows.Count).ClearContents                   
            .Range("IU:IV").ClearContents
            .Rows(1).Interior.ColorIndex = 35
            With .Range("B:B")
                .Locked = True
                .FormulaHidden = False
            End With
            .Range("B1") = "INVOICE_NR"
        End With
    End With
    MsgBox "Le fichier 'outgoing invoice' est Dévérouillé", vbInformation, "Confirmation"
    Application.Calculation = xlCalculationAutomatic
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2010] Fonction VBA qui ne fonctionne plus sous excel 2010
    Par Outinet dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 16/10/2012, 13h49
  2. Réponses: 9
    Dernier message: 13/11/2008, 15h47
  3. Réponses: 3
    Dernier message: 06/11/2007, 09h54
  4. Réponses: 4
    Dernier message: 10/04/2006, 08h28
  5. [Eclipse3]Ctrl H ne fonctionne plus sous la perspective Java
    Par joseph_p dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 30/09/2005, 11h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo