vba在excel中创建一个目录窗体;如何利用加载宏建立控件与目标文件的超级链接,请高手指点

例如:目标文件在D:/,

Sub 设置超链接()
Dim strSrcPath$, lngRow&, objFso As Object, objFile As Object
Set objFso = CreateObject("Scripting.FileSystemObject")
Dim objFldlg As FileDialog
Set objFldlg = Application.FileDialog(msoFileDialogFolderPicker)
With objFldlg
.AllowMultiSelect = False
.Title = "请选择需要建立超链接的文件夹"
.InitialFileName = ThisWorkbook.Path
If .Show = -1 Then
Range("b2").Resize(10000).ClearContents
lngRow = 1
strSrcPath = .SelectedItems(1) & IIf(Right(.SelectedItems(1), 1) = "\", "", "\")
For Each objFile In objFso.GetFolder(strSrcPath).Files
lngRow = lngRow + 1
ActiveSheet.Hyperlinks.Add Anchor:=Cells(lngRow, 2), _
Address:=strSrcPath & objFile.Name, SubAddress:="", _
ScreenTip:=objFile.Name, TextToDisplay:=objFile.Name
Next objFile
End If
End With
Set objFldlg = Nothing
Set objFile = Nothing
Set objFso = Nothing
CreateObject("Wscript.Shell").Popup "Done...", 2, "^o^", vbOKOnly
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-31
vba各种调试及解决
相似回答