Sometimes editing weldments cutlists causes some deleted folder to become invisible and their folder name cannot be used to rename the other cutlist folders, since it is already in use.
One reddit user posted the macro below, he got close to make it work, but missed the correct way to delete the multiple selection of invisible folders.
I tested the macro a couple of times with files that had like a dozen of “ghost folders” inside.
Option Explicit
Sub Main()
Dim SwApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Set SwApp = Application.SldWorks
Set swModel = SwApp.ActiveDoc
If swModel Is Nothing Then MsgBox ("Open a part"): Exit Sub
If swModel.GetType <> swDocumentTypes_e.swDocPART Then MsgBox ("Open a part"): Exit Sub
swModel.ClearSelection2 True
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
Set swSubFeat = swFeat.GetFirstSubFeature
While Not swSubFeat Is Nothing
CleanFolderName swModel, swSubFeat
Set swSubFeat = swSubFeat.GetNextSubFeature
Wend
Set swFeat = swFeat.GetNextFeature
Wend
'edited this line to make it work.
'You may add a counter to delete only if the selection is >0 elements
swmodel.extension.deleteselection2(0)
End Sub
Sub CleanFolderName(swModel As SldWorks.ModelDoc2, swFeat As SldWorks.Feature)
Dim swCutFolder As SldWorks.BodyFolder
If swFeat.GetTypeName2 <> "CutListFolder" Then Exit Sub
Set swCutFolder = swFeat.GetSpecificFeature2
If swCutFolder Is Nothing Then Exit Sub
If swCutFolder.GetBodyCount > 0 Then Exit Sub
Debug.Print "'" & swFeat.Name & "' CutListFolder Deleted"
swFeat.Select2 True, -1
End Sub