Find a component folder by name and create a new subfolder

Public Function NewComponentsFolder(FolderName As String, _
        Optional ParentFolder) _
        As ComponentFolder
    
    Dim generalComponentFolderFactory As ComponentFolderFactory
    Dim rootComponentFolderFactory As ComponentFolderFactory
    Dim cFolder As ComponentFolder, rootCFolder As ComponentFolder
    
'-----------------------------------------------------------
' Find a component folder by name and create a new subfolder
'
' This example creates a new folder at the specified location.
' If no parent path is supplied, the folder is created at the highest level
' under the root.
'-----------------------------------------------------------

    ' Get a ComponentFolderFactory from the TDConnection object
    Set generalComponentFolderFactory = tdc.ComponentFolderFactory
    
    ' Get the parent folder, either the root or the folder passed as
    '    the ParentFolder argument.
    If IsMissing(ParentFolder) Then
        ' Get the root folder
        Set rootCFolder = generalComponentFolderFactory.Root
    Else
        'Example of path: "Components\myCompFolder"
        Set rootCFolder = generalComponentFolderFactory.FolderByPath(ParentFolder.Path)
    End If
    Debug.Print rootCFolder.name
    
    Set rootComponentFolderFactory = rootCFolder.ComponentFolderFactory
 
    
    ' Add the new folder
    Set cFolder = rootComponentFolderFactory.AddItem(Null)
    cFolder.name = FolderName
    
    Debug.Print cFolder.Virtual
    
    ' Post to Server
    cFolder.Post
    
    Debug.Print cFolder.Virtual
    ' Return the new folder
    Set NewComponentsFolder = cFolder
    
End Function