- 帖子
- 73
- 主題
- 11
- 精華
- 0
- 積分
- 100
- 點名
- 0
- 作業系統
- Win 8
- 軟體版本
- 2007
- 閱讀權限
- 20
- 性別
- 女
- 註冊時間
- 2013-5-11
- 最後登錄
- 2018-7-25
 
|
回復 5# Hsieh
版大我有看完你PO的文,Sub list_and_link1 可以列出所有檔案名
----------------------------------------------------------------------------------------------------------
另外也找了一種方法,它可以幫我找出所有檔案名稱,但有個小小問題,
如果Sheet1的Range("A1") 是搜尋的檔名,例如:file(如主題中的附件),如何在搜尋到後打開他???感謝您^^
Public Sub TestListDir()
Worksheets(1).Cells(2, 1).Activate
Call listDir("C:\Users\ui\Desktop\New folder\", 1)
End Sub
Public Sub listDir(strPath As String, lngSheet As Long)
Dim strFn As String
Dim strDirList() As String
Dim lngArrayMax, x As Long
lngArrayMax = 0
strFn = Dir(strPath & "*.*", 23)
While strFn <> ""
If strFn <> "." And strFn <> ".." Then
If (GetAttr(strPath & strFn) And vbDirectory) = vbDirectory Then
lngArrayMax = lngArrayMax + 1
ReDim Preserve strDirList(lngArrayMax)
strDirList(lngArrayMax) = strPath & strFn & "\"
Else
ActiveCell.Value = strPath & strFn
Worksheets(lngSheet).Cells(ActiveCell.Row + 1, 1).Activate
End If
End If
strFn = Dir()
Wend
If lngArrayMax <> 0 Then
For x = 1 To lngArrayMax
Call listDir(strDirList(x), lngSheet)
Next
End If
End Sub |
|