Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Remove all macros and objects in Excel, Save and Quit

Hi Everyone,
I have a code in excel that after processing saves to a new name, and
tries to remove all the code from the activeworkbook, save all the open

workbooks and quits Excel.

The problem is:


The Standard module and the form do not get deleted after the saved
workbook is opened. Though the code gets deleted from the objects.


Any ideas on why this is happening. Here's the code.


Sub main()
RemoveAllMacros Activeworkbook
End sub


Sub RemoveAllMacros(ByVal objdocument As Object)


' deletes all VBProject components from objDocument
' removes the code from built-in components that can't be deleted
' use like this: RemoveAllMacros ActiveWorkbook ' in Excel
' requires a reference to the
' Microsoft Visual Basic for Applications Extensibility library
'Dim objdocument As Workbook
Dim i, l As Long
Dim w As Workbook


If objdocument Is Nothing Then Exit Sub
i = 0
On Error Resume Next
i = objdocument.VBProject.VBComponents.count
On Error GoTo 0
If i < 1 Then ' no VBComponents or protected VBProject
MsgBox "The VBProject in " & objdocument.Name & _
" is protected or has no components!", _
vbInformation, "Remove All Macros"
Exit Sub
End If
With objdocument.VBProject
For i = .VBComponents.count To 1 Step -1
l = 1
On Error Resume Next
l = .VBComponents(i).CodeModule.CountOfLines
.VBComponents(i).CodeModule.DeleteLines 1, l
' clear lines
On Error GoTo 0
Next i
End With
With objdocument.VBProject
For i = .VBComponents.count To 1 Step -1
'On Error Resume Next
If (.VBComponents(i).Type = vbext_ct_StdModule Or _
.VBComponents(i).Type = vbext_ct_MSForm) Then
.VBComponents.remove .VBComponents(i)
End If
' delete the component
'On Error GoTo 0
Next i
End With


Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each w In Application.Workbooks
w.Save
Next w


For Each w In Application.Workbooks
w.Saved = True
Next w


Set objdocument = Nothing
Application.ScreenUpdating = True
'Application.DisplayAlerts = True
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
Is there a way to remove old cell format objects from Excel? DavidFarnsworth Excel Discussion (Misc queries) 0 January 13th 07 05:00 AM
Remove all macros and objects in Excel, Save and Quit [email protected] Excel Discussion (Misc queries) 0 June 2nd 06 12:24 PM
remove hyperlinks from objects in the excel workbook using vb asmita Excel Programming 1 July 18th 05 02:46 PM
Remove macros on save as Quake Excel Programming 2 October 22nd 04 01:19 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM


All times are GMT +1. The time now is 11:44 PM.

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

About Us

"It's about Microsoft Excel"