Hi ananth
Not too sure whether it can be done. This code will return 0 for unlocked and 1 for Locked, but it is read only!
MsgBox Application.VBE.ActiveVBProject.Protection
Maybe it will put you on the right track. If you do find a way I would very interested also.
Dave
OzGrid Business Applications
You could try this routine (modified) to protect
OR unprotect the VBA project.
Const BreakIt As String = "%{F11}%TE+{TAB}{RIGHT}%V{+}{TAB}"
Sub Change_VBA_PW()
Dim WB As Workbook
Dim Password As String
Set WB = ActiveWorkbook
Password = "test"
Call SetVBProjectPassword(WB, Password)
End Sub
Sub SetVBProjectPassword(WB As Workbook, ByVal Password As String)
'Needs reference to Visual Basic for Applications Extensibility Library
Dim VBP As VBProject, openWin As VBIDE.Window
Dim wbActive As Workbook
Dim i As Integer
Set VBP = WB.VBProject
Set wbActive = ActiveWorkbook
Application.ScreenUpdating = False
' close any code windows to ensure we hit the right project
For Each openWin In VBP.VBE.Windows
If InStr(openWin.Caption, "(") > 0 Then openWin.Close
Next oWin
WB.Activate
Application.OnKey "%{F11}"
SendKeys BreakIt & Password & "{tab}" & Password & "~%{F11}", True
Application.ScreenUpdating = True
wbActive.Activate
End Sub
Ivan
I interesting stuff!
OzGrid Business Applications
Maybe my version of excel is different but, when I "save as" the worksheet my code is still protected with password