Office) (ScopeFolder 物件
對應至可搜尋的資料夾。 ScopeFolder 物件適用于 SearchFolders 集合。
註解
當您想要搜尋特定資料夾時,可以使用 SearchScope 物件和 ScopeFolders 集合的方法和屬性來擷取 ScopeFolder 物件,並將其新增至 SearchFolders 集合。
在每個 ScopeFolder 物件中,都有一個 ScopeFolders 集合,其中包含父 ScopeFolder 物件的子資料夾。 您可以周遊搜尋範圍的整個資料夾結構 (例如,所有本機磁片磁碟機) ,方法是迴圈流覽這些 ScopeFolders 集合,並傳回所有較低層級的 ScopeFolder 物件。 沒有子檔 夾的 ScopeFolder 物件包含空的 ScopeFolders 集合。
如需示範如何在搜尋範圍中迴圈查看所有 ScopeFolder 物件的範例,請參閱 SearchFolders 集合主題。
使用SearchFolders集合的Add方法,將ScopeFolder物件新增至SearchFolders集合;不過,使用您想要新增之ScopeFolder的AddToSearchFolders方法通常比較簡單,因為所有搜尋都只有一個SearchFolders集合。
如需示範如何將 ScopeFolder 新增至 SearchFolders 集合的範例,請參閱 SearchFolders 集合主題。
範例
使用SearchScope物件的ScopeFolder屬性可傳回搜尋範圍的根ScopeFolder物件;例如:
Set sf = SearchScopes.Item(1).ScopeFolder
使用ScopeFolders集合的Item屬性可傳回根ScopeFolder物件的子資料夾;例如:
Set sf = SearchScopes.Item(1).ScopeFolder.ScopeFolders.Item(1)
下列範例會顯示 [我的電腦] 中每個目錄的根路徑。 為了擷取這項資訊,此範例會先取得 [我的電腦] 根目錄的 ScopeFolder 物件。 這個 ScopeFolder 物件的路徑一律為 「*」。 如同所有 ScopeFolder 物件,根物件包含 ScopeFolders 集合。 本範例會迴圈查看這個 ScopeFolders 集合,並顯示其中每個 ScopeFolder 物件的路徑。 這些 ScopeFolder 物件的路徑會是 A:\
、 C:\
等等。
Sub DisplayRootScopeFolders()
'Declare variables that reference a
'SearchScope and a ScopeFolder object.
Dim ss As SearchScope
Dim sf As ScopeFolder
'Loop through the SearchScopes collection
'and display all of the root ScopeFolders collections in
'the My Computer scope.
For Each ss In SearchScopes
Select Case ss.Type
Case msoSearchInMyComputer
'Loop through each ScopeFolder object in
'the ScopeFolders collection of the
'SearchScope object and display the path.
For Each sf In ss.ScopeFolder.ScopeFolders
MsgBox "ScopeFolder object's path: " & sf.Path
Next sf
Case Else
End Select
Next
End Sub
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應