Protect Excel VBA Project from another Excel Macro

R

Ram Chepyala

Hi
I am opening a existing workbook using an excel macro and adding a
module with some code and i am using send keys to protect the VBA
project of the opened work book. But unfotunately it adds the password
and protects the excel sheet which has the orginal macro.
below is teh code iam using, can anybody suggest me a different
solutions or modification sto the code
Sub ProtectVBProject(WB As Workbook, ByVal Password As String)
Dim vbProj As Object
Set vbProj = WB.VBProject
'can't do it if already locked!
If vbProj.Protection = 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = vbProj
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & Password & "{TAB}" & _
Password & "~"
Application.VBE.CommandBars(1).FindControl(Id:=2578,
recursive:=True).Execute
WB.Save
End Sub

Many thanks in advance

Regards
Ram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top