excelvba read一個 folder d file名

2011-02-23 11:47 pm
我想用excel vba program read 一個特定folder 內所有的file name.用一個array 載住它。我可以怎麼做?

我連按F1都不知道search 什麼@@“”

thanks a lot!!

回答 (2)

2011-02-24 1:49 am
'若不明白, 可再發問


Dim strDrive As String
Dim strFileName As String

On Error Resume Next

Dim objFolder As Object, strPictFullPath As String

'讓用家選擇folder
Set objFolder = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please Select Image Folder", 0, GetDrive)

'folder 不是空白才讀文件
If Not objFolder Is Nothing Then
'// Is it the Root Dir?...if so change
If Len(objFolder.Items.Item.path) > 3 Then
strPictFullPath = objFolder.Items.Item.path & Application.PathSeparator
Else
strPictFullPath = objFolder.Items.Item.path
End If
Else
Exit Sub
End If



strDrive = strPictFullPath
strFileName = Dir$(strDrive & "*.tif", vbDirectory)

Do While (Len(strFileName) > 0)

' See if we should skip this file.
If Not (strFileName = ".") Or (strFileName = "..") Then

'對檔案做的動作

End If

' Get the next file.
strFileName = Dir$()
Loop

'當folder沒下一個檔案便停止

2011-02-23 17:50:25 補充:
strFileName 就是 檔案的名稱, 你可做個array 儲起佢


收錄日期: 2021-04-16 12:18:09
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20110223000051KK00520

檢視 Wayback Machine 備份