Problème macro déprotection

  • Initiateur de la discussion Initiateur de la discussion f1f00
  • 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 !

f1f00

XLDnaute Occasionnel
Salut a tous j'ai un petit problème au niveau d'une macro me servant à déprotéger des classeurs. Un message d'erreur me dit que le mdp n'est pas correct alors qu'il l'est en fait. Pourriez vous m'aider voici le code.

Code:
Option Explicit

Sub UnProtectMany()
Dim vaFileName As Variant
Dim MyDir$
MyDir = Sheets("iZiCompta").Range("C21").Text
'the location of the workbooks

With Application.FileSearch
    .NewSearch
    .LookIn = MyDir
    'the directory to search in
    .SearchSubFolders = False
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute > 0 Then
    'workbooks found
        For Each vaFileName In .FoundFiles
        'loop through each found workbook
            Unprotect vaFileName
            'pass workbook fullname to unprotect routine
        Next
    Else
        MsgBox "Aucun fichier Excel trouvé."
    End If
End With

End Sub

Sub Unprotect(wbkName)
Dim ws As Worksheet

With Application
    .ScreenUpdating = False
    .AskToUpdateLinks = False
End With

Workbooks.Open Filename:=wbkName, IgnoreReadOnlyRecommended:=True

With ActiveWorkbook
    .RunAutoMacros xlAutoOpen
    .Unprotect Password:="otersav"
    For Each ws In .Worksheets
        ws.Unprotect Password:="otersav"
    Next ws
    .Close True
End With

End Sub
 
Re : Problème macro déprotection

Bonjour f1f00,

Sans approfondir ton code, un premier survol montre que tu utilises un mot-clé (UnProtect) comme nom d'une Sub :
Code:
Sub Unprotect(wbkName)

L'erreur vient peut-être de là. Essaies de changer le nom de cette procédure.

Espérant t'avoir aidé.

Cordialement.
 
Re : Problème macro déprotection

J'ai changé et j'ai toujours le même problème

Code:
Option Explicit

Sub UnProtectMany()
Dim vaFileName As Variant
Dim MyDir$
MyDir = Sheets("Boutons").Range("B18").Text
'the location of the workbooks

With Application.FileSearch
    .NewSearch
    .LookIn = MyDir
    'the directory to search in
    .SearchSubFolders = False
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute > 0 Then
    'workbooks found
        For Each vaFileName In .FoundFiles
        'loop through each found workbook
            WkUnprotect vaFileName
            'pass workbook fullname to unprotect routine
        Next
    Else
        MsgBox "Aucun fichier Excel trouvé."
    End If
End With

End Sub

Sub WkUnprotect(wbkName)
Dim ws As Worksheet

With Application
    .ScreenUpdating = False
    .AskToUpdateLinks = False
End With

Workbooks.Open Filename:=wbkName, IgnoreReadOnlyRecommended:=True

With ActiveWorkbook
    .RunAutoMacros xlAutoOpen
    .Unprotect Password:="otersav"
    For Each ws In .Worksheets
        ws.Unprotect Password:="otersav"
    Next ws
    .Close True
End With

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 Excel VBA
Réponses
5
Affichages
585
Réponses
5
Affichages
932
Réponses
7
Affichages
459
Réponses
4
Affichages
743
Retour