Gruppe
VBE
Problem
Wie kann ich alle Module und UserForms einer Arbeitsmappe löschen und danach die Module und UserForms des aktuellen Unterverzeichnisses laden?
StandardModule: basMain
Sub DeleteAndImport()
Dim col As New Collection
Dim vbc As VBComponent
Dim iCounter As Integer
Dim sPath As String
sPath = Application.Path & "\"
For Each vbc In ThisWorkbook.VBProject.VBComponents
If vbc.Type <> 3 And _
vbc.Type < 100 And _
vbc.Name <> "basMain" Then
vbc.Export sPath & vbc.Name & ".bas"
col.Add sPath & vbc.Name & ".bas"
ThisWorkbook.VBProject.VBComponents.Remove vbc
ElseIf vbc.Type = 3 Then
vbc.Export sPath & vbc.Name & ".frm"
col.Add sPath & vbc.Name & ".frm"
ThisWorkbook.VBProject.VBComponents.Remove vbc
End If
Next vbc
For iCounter = 1 To col.Count
ThisWorkbook.VBProject.VBComponents.Import col(iCounter)
Kill col(iCounter)
Next iCounter
MsgBox "Ex- und Import abgeschlossen!"
End Sub
ClassModule: Tabelle1
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub