Microsoft Office Tutorials and References
In Depth Information
Creating a Folder Tree Menu
' * * * * *¶
Sub CreateFolderTreeMenu()¶
'Variable declaration¶
Dim aLevOneEntries() As String¶
Dim cb As Office.CommandBar¶
Dim ctlPopupMain As Office.CommandBarPopup¶
Dim i As Long¶
'Get the list of files and folders from the¶
'base folder specified in the Const BaseFolderPath¶
aLevOneEntries() = GetMenuEntries(BaseFolderPath)¶
'Make sure the changes will be stored in¶
'the template¶
CustomizationContext = NormalTemplate¶
'Specify in which toolbar the new menu¶
'will be created¶
Set cb = CommandBars(ToolbarTarget)¶
'Check to see if the button already exists¶
'and remove it if it does¶
If buttonExists(cb, ButtonName) = True Then¶
End If¶
'Create the top-level drop-down¶
'at the end of the toolbar¶
Set ctlPopupMain = CreateNewPopup(cb, ButtonName, 0)¶
'Create entries for first-level files¶
For i = LBound(aLevOneEntries, 2) To UBound(aLevOneEntries, 2)¶
'Ignore any empty entries¶
If Len(aLevOneEntries(0, i)) <> 0 Then¶
CreateMenuButton ctlPopupMain.CommandBar, aLevOneEntries(0,
i), BaseFolderPath¶
End If¶
Next i¶
'Create entries for first-level sub-folders¶
'Loop through folders in reverse order since¶
'each successive folder entry is inserted¶
'at the top of the list. Keeps them alphabetical¶
For i = UBound(aLevOneEntries, 2) To LBound(aLevOneEntries, 2) Step
If Len(aLevOneEntries(1, i)) <> 0 Then¶
'Variable declaration¶
Dim newPopup As Office.CommandBarPopup¶
'Create the popup entry¶
'position it at the top of the list (1)¶
Set newPopup = CreateNewPopup(ctlPopupMain.CommandBar,
aLevOneEntries(1, i), 1)¶
'Process the lists for the second level popup¶
'Variable declaration¶
Dim aLevTwoEntries() As String¶
Dim LevTwoPath As String¶
Dim j As Long¶
LevTwoPath = BaseFolderPath & aLevOneEntries(1, i) & "\"¶
Search JabSto ::

Custom Search