Vba 搜索当前文件夹
此Excel VBA代码创建指向a列中项目列表的超链接,以及从固定位置指向相应文件夹名称的超链接。例如:Vba 搜索当前文件夹,vba,excel,Vba,Excel,此Excel VBA代码创建指向a列中项目列表的超链接,以及从固定位置指向相应文件夹名称的超链接。例如: Room101 is hyperlinked to C:\Files\Pictures\Room101 Room102 is hyperlinked to C:\Files\Pictures\Room102 Room103 is hyperlinked to C:\Files\Pictures\Room103 我一直在尝试重新设计文件夹目标,使其更具动态性,特别是搜索文件夹应为E
Room101 is hyperlinked to C:\Files\Pictures\Room101
Room102 is hyperlinked to C:\Files\Pictures\Room102
Room103 is hyperlinked to C:\Files\Pictures\Room103
我一直在尝试重新设计文件夹目标,使其更具动态性,特别是搜索文件夹应为Excel文件的当前文件夹。请参见下面第7行的代码:
Option Explicit
Dim lngRow
Public Sub Aufruf()
Dim lngTMP As Long
lngTMP = ActiveSheet.Cells(Cells(Rows.Count, "A").End(xlUp).Row, 1).Row
For lngRow = 1 To lngTMP
searchDir "M:\Pictures" 'fixed folder location
Next lngRow
End Sub
Private Sub searchDir(strDir)
Dim objSubDir As Object
Dim strName As String
Dim objFSO As Object
Dim objDir As Object
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.getfolder(strDir)
For Each objSubDir In objDir.subfolders
strName = StrReverse(Split(StrReverse(objSubDir.Path), "\")(0))
If strName = Cells(lngRow, 1).Text Then
ActiveSheet.Hyperlinks.Add Anchor:=Cells(lngRow, 1), Address:= _
objSubDir.Path & "\", TextToDisplay:=Cells(lngRow, 1).Text
Exit Sub
End If
searchDir objSubDir
Next
Set objFSO = Nothing
Set objDir = Nothing
End Sub
您会注意到文件路径固定为“M:\Pictures”
如何搜索保存Excel文档的文件夹?我已尝试使用以下变体:
path = ActiveWorkbook.Path
VB.Net不是vba,也不是VBNet.HasMacros()=FalseTry
searchDir thisWorkbook.Path
。但是为什么lngRow=1到lngTMP的循环是?多亏了这一点,我将继续测试它。VB.Net不是vba,也是VBNet.HasMacros()=falsesearchDir thisWorkbook.Path
。但是为什么lngRow=1到lngTMP的这个循环?多亏了它的工作,我将继续测试它。