【发布时间】:2019-03-30 13:31:53
【问题描述】:
下面的 VBA 允许用户选择一个文件夹,然后完整路径显示在活动工作表的第 1 列中。
如何修改这些路径以用作超链接?
Option Explicit
Sub cmdList()
Dim sPath As String
Dim fOut As Variant
Dim r As Integer
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select directory"
.InitialFileName = ThisWorkbook.Path & "\"
.AllowMultiSelect = False
If .Show = 0 Then Exit Sub
sPath = .SelectedItems(1)
End With
fOut = Split(CreateObject("WScript.Shell").exec("cmd /c dir """ & sPath & """ /a:-h-s /b /s").StdOut.ReadAll, vbNewLine)
r = 5
Range(r & ":" & Rows.Count).Delete
Cells(r, 1).Resize(UBound(fOut) + 1, 1).Value = WorksheetFunction.Transpose(fOut)
End Sub
谢谢!
【问题讨论】:
标签: excel vba hyperlink directory