Thanks a lot Mr. Lewis for this great solution
I applied the steps and delete each module one by one and the same with userform modules ..
After that saved my file and open it again and begin to import a module one after another and checked the Alt + F8 window ..
There is no module which cause any error
After importing all modules and userforms everything is ok now.. That's weird
I thought of a quick way to such a problem .. so I thought of exporting all modules (userforms and sheet modules and standard mouldes) then delete all in on shot
But I don't know how to import all the modules from specific path (The same workbook path and the folder name which has all the modules inside)
I need your help at this point
Here' the first part which exports all modules and then delete all ...
Sub Export_Delete_Import()
'References >> Microsoft Visual Basic for Applications Extensibility
'-------------------------------------------------------------------
Dim VBComp As VBIDE.VBComponent
Dim DestDir As String, FName As String, Ext As String
If ActiveWorkbook.Path = "" Then
MsgBox "You must first save this workbook somewhere so that it has a path.", , "Error"
Exit Sub
End If
DestDir = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & " Modules"
If Dir(DestDir, vbDirectory) = vbNullString Then MkDir DestDir
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
If VBComp.CodeModule.CountOfLines > 0 Then
Select Case VBComp.Type
Case vbext_ct_ClassModule: Ext = ".cls"
Case vbext_ct_Document: Ext = ".cls"
Case vbext_ct_StdModule: Ext = ".bas"
Case vbext_ct_MSForm: Ext = ".frm"
Case Else: Ext = vbNullString
End Select
If Ext <> vbNullString Then
FName = DestDir & "\" & VBComp.Name & Ext
If Dir(FName, vbNormal) <> vbNullString Then Kill (FName)
VBComp.Export (FName)
End If
End If
Next VBComp
Call DeleteAllVBACode
End Sub
Private Sub DeleteAllVBACode()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Set VBProj = ActiveWorkbook.VBProject
For Each VBComp In VBProj.VBComponents
If VBComp.Type = vbext_ct_Document Then
Set CodeMod = VBComp.CodeModule
With CodeMod
.DeleteLines 1, .CountOfLines
End With
Else
VBProj.VBComponents.Remove VBComp
End If
Next VBComp
End Sub
Bookmarks