View Single Post
  #1   Report Post  
Adam
 
Posts: n/a
Default Removing Module Protection Programatically

We are trying to push some new code to the our code modules in a workbook.
The issue we face right now is that the modules are protected. Is there a
way to programmatically remove the module protection. So that I can run the
bellow code so that I do not get an error accessing the protected modules.

Sub PatchWorkbook(PatchWBPath As String)
Dim ve As VBE
Dim xl As Excel.Application
Dim wb As Workbook
Dim codeModule As codeModule

Set xl = New Excel.Application
xl.EnableEvents = False
xl.DisplayAlerts = False

Set wb = xl.Workbooks.Open(PatchWBPath, False, False, , "", "", , , , ,
False)
wb.UpdateRemoteReferences = False
xl.Calculation = xlCalculationManual

Set ve = xl.VBE
Debug.Print ve.VBProjects(1).Protection

Set codeModule = ve.ActiveVBProject.VBComponents("ThisWorkbook")

wb.Save
wb.Close
Set wb = Nothing
Set xl = Nothing
End Sub

Thanks in advance!

Reg,
Adam