ich möchte gerne eine Datei, die ich mit Hilfe eines Makros aus einer Ursprungsdatei erstelle Passwort schützen.
Leider passiert bei dem unten stehen code nichts. Denke VBE.CommandBars(1) ist das Problem.
Danke für eure hilfe!
Ich habe diesen Code gefunden:
Function lock_project(wb)
If Workbooks(kunde).VBProject.Protection = 1 Then Exit Function
Set VBProj = Workbooks(wb).VBProject
Set Application.VBE.ActiveVBProject = VBProj
If VBProj.Protection = 1 Then Exit Function
With Workbooks(wb).Application
'//execute the controls to lock the project\\
.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
'//activate 'protection'\\
Application.wait Now + TimeValue("0:00:01")
.SendKeys "^{TAB}"
Application.wait Now + TimeValue("0:00:01")
'//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\\
'//enter password (password is 123 in this example)\\
.SendKeys "{ }"
Application.wait Now + TimeValue("0:00:01")
.SendKeys "{TAB}" & pw
Application.wait Now + TimeValue("0:00:01")
'//confirm password\\
.SendKeys "{TAB}" & pw
Application.wait Now + TimeValue("0:00:01")
'//scroll down to OK key\\
.SendKeys "{TAB}"
Application.wait Now + TimeValue("0:00:01")
'//click OK key\\
.SendKeys "{ENTER}"
Application.wait Now + TimeValue("0:00:01")
'the project is now locked - this takes effect
'the very next time the book's opened...
End With
End Function