【问题标题】:Create a file structure / dictionary tree in Excel VBA在 Excel VBA 中创建文件结构/字典树
【发布时间】:2019-02-26 23:09:42
【问题描述】:

我编写了一个 vba 函数,它从数据库中获取文件结构(文件夹及其子文件夹的路径)并将其保存在字典中,类似于哈希。

现在,我想创建一个工作表或一个用户表单,从字典中创建一个类似于以下内容的文件结构:

基本上是一种文件结构,用户可以在其中浏览文件夹和子文件夹,并且可以选择(例如使用复选框)来选择和取消选择最里面的文件夹(其中包含脚本,并且所有选定的脚本都将被执行..)。

在 Excel 工作表或 VBA 用户表单中是否有任何类似的结构或其他类似的结构?

【问题讨论】:

标签: excel vba file dictionary structure


【解决方案1】:

这是您可能正在寻找的东西的示例:

Sub tgr()

    Dim oFolder As Object
    Dim vStartFolder As Variant
    Dim sFolderPath As String

    'If blank, the browse window will start at computer root
    'If populated, the browse window will start at the specified folder location
    vStartFolder = ""

    'Show a Folder Browser that will let the user select a folder
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Select Folder", 0, vStartFolder)
    If oFolder Is Nothing Then Exit Sub   'Pressed cancel
    sFolderPath = oFolder.Self.Path & Application.PathSeparator

    'Folder selected, do what you need with the selected folder
    MsgBox sFolderPath

End Sub

运行将打开一个如下所示的文件夹浏览器:

【讨论】:

  • 酷。如果有人想尽早绑定到您正在使用的类型库,那么他们可以勾选 Tools->References->Microsoft Shell Controls And Automation
  • 嘿,感谢您的回复,我不知道为什么有人对此表示反对,这是一个可靠的答案。可悲的是,我从运行在 linux 服务器上的 perl-maven webframe 获取文件结构,所以我不能像这样打开它。这个想法是从 webframe 中获取文件结构,让用户浏览文件夹并选择一些他想要启动的脚本,然后将信息发送回 webframe。也许在这里使用 Excel VBA 是错误的,我刚刚编写了一些 VBA 类来访问不同项目的 webframe,所以我希望我也可以在这里使用这些功能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-06
  • 1970-01-01
  • 2016-07-03
  • 2020-05-03
  • 1970-01-01
  • 2010-10-29
相关资源
最近更新 更多