Removing Objects

  • Thread starter Thread starter Living the Dream
  • Start date Start date
L

Living the Dream

Hi Guy's

I had been using the following code quite nicely and was asked by the
operator of this WB to change the standard formButtons I had on it's
Main Sheet to Command Buttons.

suffice to say, the Kill_Code does not delete the Command Buttons..

Can anyone point me to where I need to add/Insert the
"All.Objects.Delete" code so that there are no buttons left after this
code runs please

As always

TIA

Mick

Sub KillVBCode()

Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
Dim ProcName As String
Dim WillRobinson As Integer

WillRobinson = MsgBox("[ DANGER WILL ROBINSON ] YOU ARE ABOUT
TO DELETE ALL VITAL CODES FROM THIS FILE, YA REALLY WANNA DO
THAT..????", vbYesNo)
If WillRobinson = vbYes Then

With Application.VBE
If Not .ActiveCodePane Is Nothing Then
Set .ActiveVBProject =
..ActiveCodePane.CodeModule.Parent.Collection.Parent
End If
End With

Call StopTimer

Set VBProj = ActiveWorkbook.VBProject

Set VBComp = VBProj.VBComponents("Module1")
VBProj.VBComponents.Remove VBComp

Set VBComp = VBProj.VBComponents("Module2")
VBProj.VBComponents.Remove VBComp

Set VBComp = VBProj.VBComponents("Module3")
VBProj.VBComponents.Remove VBComp

Set VBComp = VBProj.VBComponents("Module4")
VBProj.VBComponents.Remove VBComp

Set VBComp = VBProj.VBComponents("Module5")
VBProj.VBComponents.Remove VBComp

Set VBComp = VBProj.VBComponents("Module6")
VBProj.VBComponents.Remove VBComp

Rows("1:3").Select
Selection.Delete Shift:=xlUp

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

Else
Cancel = True
End If

Range("A1").Select

SetAttr "T:\Wow Vic\Wow Scheduler\WowSchedHistory - 2013.xls",
vbReadOnly


End Sub
 
Back
Top