Get the root XFolder object by given XDocument

Define the function GetRootFolder in the project script so that it is accessible from every other script sheet. This function searches recursively for the root XFolder object and if found it returns it.

Public Function GetRootFolder(pXFolder As CASCADELib.CscXFolder) As CASCADELib.CscXFolder
   If pXFolder.IsRootFolder Then
      Set GetRootFolder = pXFolder
   Else
      Set GetRootFolder = GetRootFolder(pXFolder.ParentFolder)
   End If
End Function

'Call the function GetRootFolder in events having only the XDocument as parameter
   ...
   Dim pXRootFolder As CascadeLib.CscXFolder
   Set pXRootFolder = GetRootFolder (pXDoc.ParentFolder)
   ...