Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50121

Error 50289 project is protected

$
0
0
Hi,

I have the below code for deleting all macro after my user finish saving the file as new workbook so they do not need anymore macro/VBA after. Problem is when i run to this macro it shows error 50289 project is protected. Can any one let me know how to fix this? it can be a code to unprotect the project just to enable the code?

Thank you very much --



Code:

Sub macro81()
Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
  Select Case VBComp.Type
      Case vbext_ct_StdModule, vbext_ct_MSForm, _
            vbext_ct_ClassModule
        VBComps.Remove VBComp
      Case Else
        With VBComp.CodeModule
            .DeleteLines 1, .CountOfLines
        End With
  End Select
Next VBComp
End Sub


Viewing all articles
Browse latest Browse all 50121

Trending Articles