1 pièce(s) jointe(s)
Erreur avec 'CommandBars'
Bonjour,
Je tente d'ajouter une serie de references a mon code VBA sous Excel en me servant de la fonction suivante:
Code:
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
| Sub AjoutRefernces()
With Application
'//execute the controls to lock the project\\
.VBE.CommandBars("Menu Bar").Controls("Tools").Controls("References...").Execute
'//activate 'protection'\\ 1
.SendKeys "^{DOWN}"
'//CAUTION: this either checks OR UNchecks the\\
'//"Lock Project for Viewing" checkbox, if it's already\\
'//been locked for viewing, then this will UNlock it\\
.SendKeys "{ }"
'//activate 'protection'\\ 2
.SendKeys "^{DOWN}"
'//CAUTION: this either checks OR UNchecks the\\
'//"Lock Project for Viewing" checkbox, if it's already\\
'//been locked for viewing, then this will UNlock it\\
.SendKeys "{ }"
'//activate 'protection'\\ 3
.SendKeys "^{DOWN}"
'//CAUTION: this either checks OR UNchecks the\\
'//"Lock Project for Viewing" checkbox, if it's already\\
'//been locked for viewing, then this will UNlock it\\
.SendKeys "{ }"
'//scroll down to OK key\\
.SendKeys "{TAB}"
'//click OK key\\
.SendKeys "{ENTER}"
'the project is now locked - this takes effect
'the very next time the book's opened...
End With
End Sub |
Mais en l'executant j'ai l'erreur sur la pièce joint 'erreur_VBA',
Cela dit, quand j'exécute la fonction suivante:
Code:
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
| Sub LockVBAProject()
With Application
'//execute the controls to lock the project\\
.VBE.CommandBars("Menu Bar").Controls("Tools") _
.Controls("VBAProject Properties...").Execute
'//activate 'protection'\\
.SendKeys "^{TAB}"
'//CAUTION: this either checks OR UNchecks the\\
'//"Lock Project for Viewing" checkbox, if it's already\\
'//been locked for viewing, then this will UNlock it\\
.SendKeys "{ }"
'//enter password (password is 123 in this example)\\
.SendKeys "{TAB}" & "redab"
'//confirm password\\
.SendKeys "{TAB}" & "redab"
'//scroll down to OK key\\
.SendKeys "{TAB}"
'//click OK key\\
.SendKeys "{ENTER}"
'the project is now locked - this takes effect
'the very next time the book's opened...
End With
End Sub |
Dans le but de verrouiller mon code avec mot de passe, il fonctionne très bien,
Merci d'avance pour votre aide,