VB and VBA Users Source Code: Removing VBA code from an Excel Worbook
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Removing VBA code from an Excel Worbook
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, February 26, 2002
Hits:
1220
Category:
Unspecified
Article:
The code below removes VBA code from excel workbooks. Option Explicit 'Purpose : Deletes all the VBA code from a workbook 'Inputs : oWorkbook The workbook to delete all the VBA code from. 'Outputs : Returns True on success else returns False 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 03/05/2001 13:50 'Notes : This code is distributed as is and without warranties or liability ' In no event shall the owner of the copyrights, or the authors ' of the code be liable for any loss of profit, any problems or any ' damage resulting from the use or evaluation of the code. ' i.e. BACK YOUR WORK UP FIRST!!! 'Revisions : Function WorkbookDeleteVBA(oWorkbook As Excel.Workbook) As Boolean Dim oComponent As Object Dim oComponents As Object On Error GoTo ErrFailed Set oComponents = oWorkbook.VBProject.VBComponents For Each oComponent In oComponents Select Case oComponent.Type 'vbext_ct_StdModule, vbext_ct_MSForm, vbext_ct_ClassModule Case 1, 3, 2 'Remove all VBA components oComponents.Remove oComponent Case Else 'Delete the code in the sheets oComponent.CodeModule.DeleteLines 1, oComponent.CodeModule.CountOfLines End Select Next WorkbookDeleteVBA = True Exit Function ErrFailed: Debug.Print "Error in WorkbookDeleteVBA: " & Err.Description WorkbookDeleteVBA = False End Function 'Demostration code, deletes the VBA code from a test workbook Sub Test() 'Delete the code from a test workbook WorkbookDeleteVBA Workbooks("Test.xls") End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder