"新建一個模組,複製以下程式碼進去
"動態建立工具欄控制元件,執行CreateToolBar過程看一下主介面的工具條
SubCreateToolBar()
WithApplication.CommandBars.Add(Name:="檔案管理",Position:=msoBarTop,temporary:=True)
.Visible=True
With.Controls.Add(Type:=msoControlPopup,temporary:=True)
.Caption="目錄列表C:\"
.TooltipText="C:\"
.OnAction="CreateChildFolder"
EndWith
.Caption="目錄列表D:\"
.TooltipText="D:\"
.Caption="目錄列表E:\"
.TooltipText="E:\"
.Caption="目錄列表F:\"
.TooltipText="F:\"
EndSub
PrivateSubCreateChild(ParentAsOffice.CommandBarPopup,FolderPathAsString)
DimiFolderAsString,iFileAsString,CtlAsCommandBarControl
IfRight(FolderPath,1)<>"\"ThenFolderPath=FolderPath&"\"
ForEachCtlInParent.Controls
Ctl.Delete
Next
WithParent.Controls
iFolder=Dir(FolderPath,vbDirectory)
DoWhileiFolder<>""
IfiFolder<>"."AndiFolder<>".."Then
If(GetAttr(FolderPath&iFolder)AndvbDirectory)=vbDirectoryThen
With.Add(Type:=msoControlPopup,temporary:=True)
.Caption=iFolder
.TooltipText=FolderPath&iFolder
EndIf
iFolder=Dir
Loop
iFile=Dir(FolderPath&"\*.*")
DoWhileiFile<>""
With.Add(Type:=msoControlButton,temporary:=True)
.Caption=iFile
.TooltipText=FolderPath&"\"&iFile
.OnAction="OpenFile"
iFile=Dir
PrivateSubCreateChildFolder()
DimMyPopupAsOffice.CommandBarPopup
SetMyPopup=Application.CommandBars.ActionControl
CallCreateChild(MyPopup,MyPopup.TooltipText)
PrivateSubOpenFile()
ActiveWorkbook.FollowHyperlinkCommandBars.ActionControl.TooltipText
"新建一個模組,複製以下程式碼進去
"動態建立工具欄控制元件,執行CreateToolBar過程看一下主介面的工具條
SubCreateToolBar()
WithApplication.CommandBars.Add(Name:="檔案管理",Position:=msoBarTop,temporary:=True)
.Visible=True
With.Controls.Add(Type:=msoControlPopup,temporary:=True)
.Caption="目錄列表C:\"
.TooltipText="C:\"
.OnAction="CreateChildFolder"
EndWith
With.Controls.Add(Type:=msoControlPopup,temporary:=True)
.Caption="目錄列表D:\"
.TooltipText="D:\"
.OnAction="CreateChildFolder"
EndWith
With.Controls.Add(Type:=msoControlPopup,temporary:=True)
.Caption="目錄列表E:\"
.TooltipText="E:\"
.OnAction="CreateChildFolder"
EndWith
With.Controls.Add(Type:=msoControlPopup,temporary:=True)
.Caption="目錄列表F:\"
.TooltipText="F:\"
.OnAction="CreateChildFolder"
EndWith
EndWith
EndSub
PrivateSubCreateChild(ParentAsOffice.CommandBarPopup,FolderPathAsString)
DimiFolderAsString,iFileAsString,CtlAsCommandBarControl
IfRight(FolderPath,1)<>"\"ThenFolderPath=FolderPath&"\"
ForEachCtlInParent.Controls
Ctl.Delete
Next
WithParent.Controls
iFolder=Dir(FolderPath,vbDirectory)
DoWhileiFolder<>""
IfiFolder<>"."AndiFolder<>".."Then
If(GetAttr(FolderPath&iFolder)AndvbDirectory)=vbDirectoryThen
With.Add(Type:=msoControlPopup,temporary:=True)
.Caption=iFolder
.TooltipText=FolderPath&iFolder
.OnAction="CreateChildFolder"
EndWith
EndIf
EndIf
iFolder=Dir
Loop
iFile=Dir(FolderPath&"\*.*")
DoWhileiFile<>""
With.Add(Type:=msoControlButton,temporary:=True)
.Caption=iFile
.TooltipText=FolderPath&"\"&iFile
.OnAction="OpenFile"
EndWith
iFile=Dir
Loop
EndWith
EndSub
PrivateSubCreateChildFolder()
DimMyPopupAsOffice.CommandBarPopup
SetMyPopup=Application.CommandBars.ActionControl
CallCreateChild(MyPopup,MyPopup.TooltipText)
EndSub
PrivateSubOpenFile()
ActiveWorkbook.FollowHyperlinkCommandBars.ActionControl.TooltipText
EndSub