Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default delete modules


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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default delete modules


I think you will find your answer he
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
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
delete modules and sheets mike allen[_2_] Excel Programming 1 January 9th 07 02:47 PM
Delete all modules and forms from workbook Daniel Bonallack Excel Programming 2 June 2nd 06 02:34 AM
Delete Modules in Macro Mark Excel Programming 4 March 6th 05 05:42 PM
Delete modules programmatically and save Brijesh Shah Excel Programming 3 December 24th 03 08:14 PM
Delete Modules and Userforms Peter Pantus Excel Programming 1 September 26th 03 08:17 PM


All times are GMT +1. The time now is 04:39 AM.

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"