2009-06-05 [VBA][Excel][Function] 取得完整路徑目錄下的全部檔案集合 20021 0 VBA 2009-06-08 摘要:[VBA] 取得完整路徑目錄下的全部檔案集合 'Description:取得活頁簿目錄或底下目錄的全部(指定)檔案名稱集合 - Ver. 1.05 'Parameters:wb 活頁簿、strSplitChar 分隔字元、strFolderPath 活頁簿底下目錄的路徑、strExtension 指定的副檔名 'Retrun:String 'Package: 'Reference:Microsoft Scripting Runtime 'Creater:Darren.NET - 2009/04/17 'Modify: Public Function F_File_GetFileNameArry(wb As Workbook, strSplitChar As String, strFolderPath As String, strExtension As String) As String Dim fsoFiles As Scripting.FileSystemObject Dim fsoExtension As Scripting.FileSystemObject Dim files As Scripting.files Dim file As Scripting.file Dim strCompletePath As String Set fsoFiles = New Scripting.FileSystemObject Set fsoExtension = New Scripting.FileSystemObject '判斷路徑(strFolderPath 是否有值),若不為空完整路徑為活頁簿所在路徑+底下目錄路徑, ' 若是空代表為完整路徑即為活頁簿所在路徑。 If strFolderPath <> "" Then strCompletePath = wb.path & strFolderPath Else: strCompletePath = wb.path End If '取得完整路徑目錄下的全部檔案集合 Set files = fsoFiles.GetFolder(strCompletePath).files '判斷是否有指定副檔名(strExtension 是否有值),若不為空(有指定)則須過濾檔案, ' 若是指定的副檔名才加入字串;若為空表示全部檔案名稱加入字串。 If strExtension <> "" Then For Each file In files If UCase(fsoExtension.GetExtensionName(file.Name)) = UCase(strExtension) Then If F_File_GetFileNameArry <> "" Then F_File_GetFileNameArry = F_File_GetFileNameArry + strSplitChar + file.Name Else: F_File_GetFileNameArry = file.Name End If End If Next Else For Each file In files If F_File_GetFileNameArry <> "" Then F_File_GetFileNameArry = F_File_GetFileNameArry + strSplitChar + file.Name Else: F_File_GetFileNameArry = file.Name End If Next End If Set fsoFiles = Nothing Set fsoExtension = Nothing Set files = Nothing Set file = Nothing End Function VBA Excel Function 回首頁