Thread: Delete VB code
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ChrisP ChrisP is offline
external usenet poster
 
Posts: 54
Default Delete VB code

I have a workbook that has password protected VB code (it must stay password
protected). Below is my code, my issue is that I can't delete the VB code
without entering the password but I have no clue how to do that. Any help is
appreciated!!!

Private Sub cmdMyButton4_Click()

Call BreakLinks

Application.Dialogs(xlDialogSaveAs).Show "TBD"

Call DeleteVBA

ActiveSheet.Shapes("cmdMyButton4").Delete

End Sub

Sub BreakLinks()
Dim Links As Variant
Dim i As Integer

With ActiveWorkbook
Links = .LinkSources(xlExcelLinks)
If Not IsEmpty(Links) Then
For i = 1 To UBound(Links)
.BreakLink Links(i), xlLinkTypeExcelLinks
Next i
End If
End With
End Sub

Sub DeleteVBA()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule

Set VBProj = ActiveWorkbook.VBProject

For Each VBComp In VBProj.VBComponents
If VBComp.Type = vbext_ct_Document Then
Set CodeMod = VBComp.CodeModule
With CodeMod
.DeleteLines 1, .CountOfLines
End With
Else
VBProj.VBComponents.Remove VBComp
End If
Next VBComp
End Sub