Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Removing vba code from workbook

Is it possible to program saving the current workbook without the vba code ?

Regards & TIA



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Removing vba code from workbook

Hi,

Yes it is but it also very dangerous if you make an error. However, try
this. Put this in 'ThisWorkbook' which calls the code that does the deletion

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call DeleteCode
End Sub

Then this in a general module

Sub DeleteCode()
Prompt = "Are you certain that you want to delete all the VBA Code?"
Proceed = MsgBox(Prompt, vbYesNo + vbQuestion)
If Proceed = vbNo Then
Exit Sub
End If
On Error Resume Next
With ActiveWorkbook.VBProject
For x = .VBComponents.Count To 1 Step -1
.VBComponents.Remove .VBComponents(x)
Next x
For x = .VBComponents.Count To 1 Step -1
.VBComponents(x).CodeModule.DeleteLines 1, _
.VBComponents(x).CodeModule.CountOfLines
Next x
End With
On Error GoTo 0
End Sub


Mike



"Jim" wrote:

Is it possible to program saving the current workbook without the vba code ?

Regards & TIA




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
Removing code in 'This Workbook' Mark Excel Programming 2 March 31st 05 03:41 PM
removing a toolbar with code Papa Jonah Excel Programming 4 February 22nd 05 07:49 PM
Removing Workbook_Open code GJones Excel Programming 0 September 1st 04 08:57 PM
Removing all code from a Project Stuart[_5_] Excel Programming 5 June 30th 04 12:54 AM
Removing VBA Code (programatically) Marnie R Excel Programming 1 February 13th 04 01:02 AM


All times are GMT +1. The time now is 12:24 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"