wolf.stalker
09-23-2008, 10:55 PM
Hey all. I am trying to create a macro that will run on auto open event. i have been reading up on code and send keys but just........can't.........seem to get it to work. the last bit of code i found looks like it should work, but does not :-\
can anyone help me tweak this to work? i did a similar post months ago and never got it to work, but have come back to it and will try again...
http://www.vbaexpress.com/forum/showthread.php?t=19628
Sub LockVBAProject()
With Application
'//execute the controls to lock the project\\
'the first line below ".vbe.commandbars......" is the line in which i get the error.
'error msg Run-time error '1004', app-defined or obj-def error
'******************************************************
.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}" & "123"
'//confirm password\\
.SendKeys "{TAB}" & "123"
'//scroll down to OK key\\
.SendKeys "{TAB}"
'//click OK key\\
.SendKeys "{ENTER}"
'the project is now locked - this takes effect
End With
End Sub
can anyone help me tweak this to work? i did a similar post months ago and never got it to work, but have come back to it and will try again...
http://www.vbaexpress.com/forum/showthread.php?t=19628
Sub LockVBAProject()
With Application
'//execute the controls to lock the project\\
'the first line below ".vbe.commandbars......" is the line in which i get the error.
'error msg Run-time error '1004', app-defined or obj-def error
'******************************************************
.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}" & "123"
'//confirm password\\
.SendKeys "{TAB}" & "123"
'//scroll down to OK key\\
.SendKeys "{TAB}"
'//click OK key\\
.SendKeys "{ENTER}"
'the project is now locked - this takes effect
End With
End Sub