PC Review


Reply
Thread Tools Rate Thread

delete modules

 
 
sunilpatel
Guest
Posts: n/a
 
      26th Jun 2009

i want to remove all modules of code and delete all sheets excep those
starting with the word "FULL"
here is my attempt but, the residual file is always corrupt, and connot be
opened. Can someone please tell me where im am going wrong. (Excel 2000)

Sunil

Sub removecode()
Dim sh As Worksheet
Dim vbCom As Object
For Each sh In ActiveWorkbook.Sheets
If Left$(sh.NAME, 5) = "FULL " Then
sh.Visible = xlSheetVisible: GoTo NxSht:
Else
sh.Delete
End If
NxSht:
Next sh

Application.WindowState = xlMinimized
Application.EnableEvents = False
Application.DisplayAlerts = False
On Error Resume Next
For X% = 10 To 2 Step -1 ' **this code is in module1
Set vbCom = Application.VBE.ActiveVBProject.VBComponents
vbCom.Remove VBComponent:=vbCom.ITEM("Module" & X%)
Next X%

ActiveWorkbook.Save
Application.Quit
End Sub


 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      26th Jun 2009

I think you will find your answer here:
http://www.cpearson.com/excel/vbe.aspx

HTH,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"sunilpatel" wrote:

> i want to remove all modules of code and delete all sheets excep those
> starting with the word "FULL"
> here is my attempt but, the residual file is always corrupt, and connot be
> opened. Can someone please tell me where im am going wrong. (Excel 2000)
>
> Sunil
>
> Sub removecode()
> Dim sh As Worksheet
> Dim vbCom As Object
> For Each sh In ActiveWorkbook.Sheets
> If Left$(sh.NAME, 5) = "FULL " Then
> sh.Visible = xlSheetVisible: GoTo NxSht:
> Else
> sh.Delete
> End If
> NxSht:
> Next sh
>
> Application.WindowState = xlMinimized
> Application.EnableEvents = False
> Application.DisplayAlerts = False
> On Error Resume Next
> For X% = 10 To 2 Step -1 ' **this code is in module1
> Set vbCom = Application.VBE.ActiveVBProject.VBComponents
> vbCom.Remove VBComponent:=vbCom.ITEM("Module" & X%)
> Next X%
>
> ActiveWorkbook.Save
> Application.Quit
> End Sub
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Delete all modules but 1 John Spencer Microsoft Access Queries 1 10th Jul 2008 12:41 PM
delete modules and sheets mike allen Microsoft Excel Programming 1 9th Jan 2007 02:47 PM
Delete modules in another file MikeP Microsoft Excel Discussion 1 24th Jan 2006 04:27 PM
Delete Modules in Macro =?Utf-8?B?TWFyaw==?= Microsoft Excel Programming 4 6th Mar 2005 05:42 PM
Delete Modules and Userforms Peter Pantus Microsoft Excel Programming 1 26th Sep 2003 08:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:06 AM.