Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Deleting code from a macro (by a macro)

Hi there

I want to delete some code from a PRIVATE SUB in the sheet code after it has
been used. I copied the following code from Chip Pearson's web site but it
comes up with an error (it doesn't seem to like VBIDE very much). I have
checked the trust VB code checkbox in security options.

Sub DeleteAllVBA()

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
My preference would be just to delete the code rather than the whole VB
Project, but it doesn't really matter. My understanding is that you can't
delete code from a Private sub anyway


Sub DeleteAllCodeInModule()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("Worksheet_Cha nge").CodeModule
With VBCodeMod
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With
'Private Sub Worksheet_Change
End Sub

This doesn't work either.


Can someone help please?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Deleting code from a macro (by a macro)

I think you missed this paragraph from Chip's page (near the top):

Before using these procedures, you'll need to set a reference in VBA to the VBA
Extensibility library. In the VBA editor, go to the Tools menu, choose the
References item, and put a check next to "Microsoft Visual Basic For
Applications Extensibility" library. This enables VBA to find the definitions
of these objects. If you are using Excel97, this library will appear in the
References list without a version number: "Microsoft Visual Basic For
Applications Extensibility". If you are using Excel 2000 or later, it will
appear with a version number: "Microsoft Visual Basic For Applications
Extensibility 5.3". It is very important that you reference the proper
library. If you reference the wrong library, you will receive "Type Mismatch"
errors. If you don't reference the extensibility library at all, you will
receive "User Defined Type Not Defined Error" messages.





Brettjg wrote:

Hi there

I want to delete some code from a PRIVATE SUB in the sheet code after it has
been used. I copied the following code from Chip Pearson's web site but it
comes up with an error (it doesn't seem to like VBIDE very much). I have
checked the trust VB code checkbox in security options.

Sub DeleteAllVBA()

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
My preference would be just to delete the code rather than the whole VB
Project, but it doesn't really matter. My understanding is that you can't
delete code from a Private sub anyway

Sub DeleteAllCodeInModule()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("Worksheet_Cha nge").CodeModule
With VBCodeMod
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With
'Private Sub Worksheet_Change
End Sub

This doesn't work either.

Can someone help please?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 295
Default Deleting code from a macro (by a macro)

Hi Dave, I think you might be right!. Thankyou for that.
Regards, Brett

"Dave Peterson" wrote:

I think you missed this paragraph from Chip's page (near the top):

Before using these procedures, you'll need to set a reference in VBA to the VBA
Extensibility library. In the VBA editor, go to the Tools menu, choose the
References item, and put a check next to "Microsoft Visual Basic For
Applications Extensibility" library. This enables VBA to find the definitions
of these objects. If you are using Excel97, this library will appear in the
References list without a version number: "Microsoft Visual Basic For
Applications Extensibility". If you are using Excel 2000 or later, it will
appear with a version number: "Microsoft Visual Basic For Applications
Extensibility 5.3". It is very important that you reference the proper
library. If you reference the wrong library, you will receive "Type Mismatch"
errors. If you don't reference the extensibility library at all, you will
receive "User Defined Type Not Defined Error" messages.





Brettjg wrote:

Hi there

I want to delete some code from a PRIVATE SUB in the sheet code after it has
been used. I copied the following code from Chip Pearson's web site but it
comes up with an error (it doesn't seem to like VBIDE very much). I have
checked the trust VB code checkbox in security options.

Sub DeleteAllVBA()

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
My preference would be just to delete the code rather than the whole VB
Project, but it doesn't really matter. My understanding is that you can't
delete code from a Private sub anyway

Sub DeleteAllCodeInModule()
Dim VBCodeMod As CodeModule
Dim StartLine As Long
Dim HowManyLines As Long

Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("Worksheet_Cha nge").CodeModule
With VBCodeMod
StartLine = 1
HowManyLines = .CountOfLines
.DeleteLines StartLine, HowManyLines
End With
'Private Sub Worksheet_Change
End Sub

This doesn't work either.

Can someone help please?


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting a macro completely sgreene Excel Discussion (Misc queries) 2 October 19th 06 05:37 PM
Deleting rows with macro PhilScratchingmyhead Excel Worksheet Functions 2 June 29th 06 05:55 PM
Deleting Row Macro Steve M Excel Worksheet Functions 4 April 20th 06 03:42 PM
Deleting a macro scottech Excel Discussion (Misc queries) 5 December 5th 05 05:02 PM
Macro is deleting everything! vmagal1 Excel Discussion (Misc queries) 3 April 25th 05 06:05 PM


All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"