| {\rtf1\ansi\ansicpg1252\deff0\deflang1044{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}} \viewkind4\uc1\pard\f0\fs17 The code below removes VBA code from excel workbooks. \par \par Option Explicit \par \par 'Purpose : Deletes all the VBA code from a workbook \par 'Inputs : oWorkbook The workbook to delete all the VBA code from. \par 'Outputs : Returns True on success else returns False \par \par \par Function WorkbookDeleteVBA(oWorkbook As Excel.Workbook) As Boolean \par Dim oComponent As Object \par Dim oComponents As Object \par \par On Error GoTo ErrFailed \par Set oComponents = oWorkbook.VBProject.VBComponents \par For Each oComponent In oComponents \par Select Case oComponent.Type \par 'vbext_ct_StdModule, vbext_ct_MSForm, vbext_ct_ClassModule \par Case 1, 3, 2 \par 'Remove all VBA components \par oComponents.Remove oComponent \par Case Else \par 'Delete the code in the sheets \par oComponent.CodeModule.DeleteLines 1, oComponent.CodeModule.CountOfLines \par End Select \par Next \par WorkbookDeleteVBA = True \par \par Exit Function \par \par ErrFailed: \par Debug.Print "Error in WorkbookDeleteVBA: " & Err.Description \par WorkbookDeleteVBA = False \par End Function \par \par 'Demostration code, deletes the VBA code from a test workbook \par Sub Test() \par 'Delete the code from a test workbook \par WorkbookDeleteVBA Workbooks("Test.xls") \par End Sub \par } |
Removing VBA code from an Excel Worbook |
India web developer web development India | India web development company India ecommerce web developer