May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.
Sub RemoveVBAFiles() Dim pVBAProject As VBProject Dim vbComp As VBComponent Dim i As Integer Dim n As Integer ' Get the VBA project ' Set pVBAProject = ThisWorkbook.VBProject Set pVBAProject = Application.Workbooks("Oz_main.xls").VBProject n = pVBAProject.VBComponents.Count For i = n To 1 Step -1 Set vbComp = pVBAProject.VBComponents.Item(i) Select Case vbComp.Type Case vbext_ct_StdModule If vbComp.Name <> "Module1" Then pVBAProject.VBComponents.Remove pVBAProject.VBComponents.Item(i) End If Case Else If vbComp.Name <> "ThisWorkbook" And vbComp.Name <> "Sheet1" Then pVBAProject.VBComponents.Remove pVBAProject.VBComponents.Item(i) End If End Select Next MsgBox "Sheet has been cleared of all modules" End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|78 files, need to delete row 2 in every file||3||33|
|drag and drop (but keep all) lines||11||46|
|ENTER A NUMBER INTO A CELL AND POPULATE OTHER CELLS BASED ON WHAT WAS ENTERED IN EXCEL PART 2||6||46|
|Resolving #VALUE error in spreadsheet||2||20|
Join the community of 500,000 technology professionals and ask your questions.