Add Default Rubberduck VBA Folder Annotation to VBProject.VBComponents Currently Rubberduck VBA files all the VBProject VBComponents in that do not have a Folder Annotation in a Folder named after the VBProject.  It can be time consuming to manually organize the components for the first time and a inconvenient to add annotations to every Worksheet, Userform, Class, ...ect.  When ran my code will organize any unfiled component by ProjectName.ComponentType.
Before

After

You will need to add a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 and from file options check &quot;Trust access to VBA project object model&quot;.

Private Sub AddDefaultFolderAnnotationsToVBComponents()
    Dim Component As VBComponent
    Dim Project As VBProject
    
    Select Case Application.Name
    Case &quot;Microsoft Access&quot;, &quot;Microsoft Word&quot;
        Set Project = IIf(True, Application, 0).VBE.ActiveVBProject
            
    Case &quot;Microsoft Excel&quot;
        Set Project = IIf(True, Application, 0).ActiveWorkbook.VBProject

    Case &quot;Microsoft PowerPoint&quot;
        Set Project = IIf(True, Application, 0).VBE.VBProjects(1)
        
    End Select
    
    Dim FolderName As String
    Dim HasFolder As Boolean
    
    For Each Component In Project.VBComponents
        With Component.CodeModule
            If .CountOfLines = 0 Then
                HasFolder = False
            Else
                HasFolder = InStr(.Lines(1, .CountOfLines), Chr(39) &amp; &quot;@Folder&quot;)
            End If
        End With
        
        If Not HasFolder Then
            Select Case Component.Type
                Case vbext_ComponentType.vbext_ct_StdModule
                    FolderName = Project.Name &amp; &quot;.Modules&quot;
                Case vbext_ComponentType.vbext_ct_ClassModule
                    FolderName = Project.Name &amp; &quot;.Classes&quot;
                Case vbext_ComponentType.vbext_ct_MSForm
                    FolderName = Project.Name &amp; &quot;.Forms&quot;
                Case vbext_ComponentType.vbext_ct_ActiveXDesigner
                    FolderName = Project.Name &amp; &quot;.Designers&quot;
                Case vbext_ComponentType.vbext_ct_Document
                    FolderName = Project.Name &amp; &quot;.Documents&quot;
            End Select
            
            Component.CodeModule.InsertLines 1, Chr(39) &amp; &quot;@Folder(&quot;&quot;&quot; &amp; FolderName &amp; &quot;&quot;&quot;)&quot;
        End If
    Next
End Sub

Note: I purposely kept all the functionality in a single procedure for portability.
Kudos to the Rubberduck team the latest version Rubberduck VBA v2.5 is a C# WPF that follows the MVVM pattern to the letter!
HasFolder = InStr(.Lines(1, .CountOfLines), Chr(39) &amp; &quot;@Folder&quot;)


That condition can technically be True in modules that don't actually have the annotation; a @Folder Rubberduck annotation is only valid in a module's declarations section, so there's no need to grab the module content any further than .CountOfDeclarationLines - if the module is nearing the 10K lines capacity, using this instead of .CountOfLines could make a significant difference in the size of the string being passed to the InStr function.

Select Case Component.Type
    Case vbext_ComponentType.vbext_ct_StdModule
        FolderName = Project.Name &amp; &quot;.Modules&quot;
    Case vbext_ComponentType.vbext_ct_ClassModule
        FolderName = Project.Name &amp; &quot;.Classes&quot;
    Case vbext_ComponentType.vbext_ct_MSForm
        FolderName = Project.Name &amp; &quot;.Forms&quot;
    Case vbext_ComponentType.vbext_ct_ActiveXDesigner
        FolderName = Project.Name &amp; &quot;.Designers&quot;
    Case vbext_ComponentType.vbext_ct_Document
        FolderName = Project.Name &amp; &quot;.Documents&quot;
End Select


I wouldn't repeat the concatenation here - just work out the last part of the name per the component type, and then concatenate with Project.Name &amp; &quot;.&quot; (I'd pull the separator dot out of the Case blocks as well) - and then I might give it a bit of breathing room, but that's more subjective:
    Select Case Component.Type
        Case vbext_ComponentType.vbext_ct_StdModule
            ChildFolderName = &quot;Modules&quot;

        Case vbext_ComponentType.vbext_ct_ClassModule
            ChildFolderName = &quot;Classes&quot;

        Case vbext_ComponentType.vbext_ct_MSForm
            ChildFolderName = &quot;Forms&quot;

        Case vbext_ComponentType.vbext_ct_ActiveXDesigner
            ChildFolderName = &quot;Designers&quot; 'note: not supported in VBA

        Case vbext_ComponentType.vbext_ct_Document
            ChildFolderName = &quot;Documents&quot;

    End Select
    FolderName = Project.Name &amp; &quot;.&quot; &amp; ChildFolderName

I like the @Folder(&quot;Parent.Child&quot;) syntax and I see that's what you're generating here:

Component.CodeModule.InsertLines 1, Chr(39) &amp; &quot;@Folder(&quot;&quot;&quot; &amp; FolderName &amp; &quot;&quot;&quot;)&quot;


Note that this would also be legal... and simpler to generate:
Component.CodeModule.InsertLines 1, &quot;'@Folder &quot; &amp; FolderName

Obviously if you prefer the parenthesized syntax (either works, it's really just down to personal preference) like I do then by all means keep it, but Rubberduck's new Move to Folder command doesn't put the parentheses in. I'd probably have the single-quote ' character spelled out, too, but I can see how a ' might be harder than necessary to read in the middle of a bunch of &quot; double quotes. On the other hand, defining a constant for it would remove the need to have the &quot;@Folder string literal defined in multiple places:
Private Const RD_FOLDER_ANNOTATION As String = &quot;'@Folder &quot;

...

Component.CodeModule.InsertLines 1, RD_FOLDER_ANNOTATION &amp; FolderName

I have to mention that Rubberduck deliberately shoves all modules under the same default named-after-the-project folder (they can easily be sorted by component type in the Code Explorer), because we strongly believe grouping modules by component type is utterly useless and counter-productive: when I look at the code for a given functionality, I want to see all the code related to that functionality - and I couldn't care less about the component type of the code I'm looking at... it's mostly all class modules anyway.
A sane way to organize the modules in a project, is by functionality: you want your ThingView user form in the same place as your ThingModel class and your ThingPresenter and the Things custom collection - that way when you're working on that Thing, you don't have to dig up the various pieces in an ever-growing list of components under some useless &quot;Class Modules&quot; folder.