Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

附註: 如果 Microsoft Jet Expression Service 在沙箱模式中執行,會停用本主題中所述的函數、方法、物件或屬性,以免評估可能不安全的表達式。 如需沙盒模式的詳細資訊,請在 [說明] 中搜尋「沙盒模式」。

回代表檔案 、目錄或資料夾屬性的整數。

語法

GetAttr ( pathname )

必要的 路徑名稱引數 是指定檔名的 字串運算式 。 路徑名稱可能包含目錄或資料夾,以及磁碟驅動器。

傳回值

GetAttr 傳回的值是下列屬性值的總和:

常數

描述

vbNormal

0

正常。

vbReadOnly

1

唯讀。

vbHidden

2

隱藏。

vbSystem

4

系統檔案。 無法在 Macintosh 上使用。

vbDirectory

16

目錄或資料夾。

vbArchive

32

自上次備份以來,檔案已變更。 無法在 Macintosh 上使用。

vbAlias

64

指定的檔名是別名。 僅適用於Macintosh。


附註: 這些常數是由 Visual Basic for Applications 指定。 名稱可用於代碼中的任何位置,以取代實際值。

註解

附註: 下列範例示範如何在 Visual Basic for Applications (VBA) 模組中使用此函數。 如需使用 VBA 的詳細資訊,請在 [搜尋] 旁的下拉式清單中選取 [開發人員參考],並在 [搜尋] 方塊中輸入一個或多個字詞。

若要判斷要設定哪些屬性,請使用 And 運算符來執行 GetAttr 函數傳回之值的 位元比較 ,以及您想要的個別檔案屬性值。 如果結果不是零,則該屬性會針對具名檔案設定。 例如,若未設定 Archive 屬性,下列 And 表達式的傳回值為零:

Result = GetAttr(FName) And vbArchive

如果已設定 Archive 屬性,則會傳回非零值。

範例

此範例使用 GetAttr 函數來判斷檔案、目錄或資料夾的屬性。 在 Macintosh 上,只有常數 vbNormal、vbReadOnly、vbHidden 和 vbAlias 可供使用。

Dim MyAttr
' Assume file TESTFILE has hidden attribute set.
MyAttr = GetAttr("TESTFILE") ' Returns 2.
' Returns nonzero if hidden attribute is
' set on TESTFILE.
Debug.Print MyAttr And vbHidden
' Assume file TESTFILE has hidden and
' read-only attributes set.
MyAttr = GetAttr("TESTFILE") ' Returns 3.
' Returns nonzero if hidden attribute is
' set on TESTFILE.
Debug.Print MyAttr And (vbHidden + vbReadOnly)
' Assume MYDIR is a directory or folder.
MyAttr = GetAttr("MYDIR") ' Returns 16.

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×