Código VBA para proteger/desproteger o Projeto VBA (Resolv)

Marco_Bertolani

27-12-2012 18:35:36

Alguém conhece um código VBA que desproteja automaticamente o projeto VBA para que os módulos possam ser excluídos?
Seria um comando tipo ActiveSheet.Unprotect, porém, para o Projeto VBA.

Grato!

Mauro Coutinho

02-01-2013 00:00:52

Marco, suponho que você tenha a Senha do Projeto, então voce pode utilizar as rotinas abaixo :

Para Proteger o Projeto:

Código: Selecionar todos

Sub ProtegeVBA()

    VBA.SendKeys "%{F11}%(FP)" & "+{TAB}{RIGHT}%B{TAB}" & "1234" & "{TAB}" & "1234" & "~", True

End Sub
Para Desproteger podemos utilizar uma das duas :

Código: Selecionar todos

Sub DesprotegeVBA()

    VBA.SendKeys "%{F11}%(FP)" & "1234" & "~" & "+{TAB}{RIGHT}%B{TAB}{DEL}{TAB}{DEL}" & "~", True

End Sub

Sub UnprotectVBAProject()

    Interaction.SendKeys "%{F11}"
    Interaction.SendKeys "^r"
    Interaction.SendKeys "{DOWN}"
    Interaction.SendKeys "1234"
    Interaction.SendKeys "{ENTER}"
    
End Sub
Veja tambem os links abaixo :
I cant unlock a vbaproject with VBA
http://stackoverflow.com/questions/1130 ... t-with-vba

Deleting Modules & Macros with Code
http://www.mrexcel.com/archive/VBA/29825.html

Unprotecting VBA Project via VBA code to change code
http://www.ozgrid.com/forum/showthread.php?t=13006

[]s