E.g. like this. (An add-in I use a lot, slightly revised--a bit more.) Select a folder in the Project pane then run the script. Everything in the folder is deleted from the project--including any subfolders and their contents. Option Explicit Dim app ' Application Dim comps ' ComponentSet Dim folder ' Component Dim i Sub Main Set app = Application Set comps = Document.ComponentSet Set folder = CurrentFolder If folder Is Nothing Then app.MessageBox "Select a folder in the Project pane" & vbCrLf & "before running the script.", _ "Empty current folder" Else If folder.Children.Count = 0 Then app.MessageBox Chr(34) & folder.Name & Chr(34) & " is already empty.", _ "Empty current folder" Else If app.MessageBoxEx("Are you sure you want to delete all components in " _ & Chr(34) & folder.Name & Chr(34) & "?", _ "Empty this folder", _ MessageBoxTypeYesNo) = MessageBoxResultYes Then With folder.Children For i = .Count - 1 To 0 Step -1 If Not IsEmpty(.Item(i).Owner) Then ' bound component: will be deleted implicitly Else app.History.Log "Delete " & Chr(34) & .Item(i).Name & Chr(34) & "..." & vbCrLf, True comps.Remove .Item(i) End If Next End With End If End If End If End Sub ' Private Function CurrentFolder ' Returns the folder selected in the Project pane ' (if any) Dim comps Dim folder Dim name Set comps = Document.ComponentSet Set folder = Nothing If comps.Count > 0 Then name = Application.UserInterface.Panes("Project").ControlSet("TreeViewComponents").Text If name <> "" Then If comps(name).Type = ComponentFolder Then Set folder = comps(name) End If End If End If Set CurrentFolder = folder End Function Attachments: Empty current folder.txt
|