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 在沙箱模式中執行,會停用本主題中所述的函數、方法、物件或屬性,以免評估可能不安全的表達式。 如需沙盒模式的詳細資訊,請在 [說明] 中搜尋「沙盒模式」。

傳回與操作系統環境變數相關聯的 String 。 無法在 Macintosh 上使用

語法

Environ ( { envstring | number } )

Environ 函數語法具有下列自變數:

引數

描述

envstring

選擇性。 包含環境變數名稱的字串表達式。

number

選擇性。 對應到環境字串數據表中環境字串數值順序的數值表達式。 number 自變數可以是任何數值表達式,但在評估之前會四捨五入至整數。


註解

如果在環境字串數據表中找不到 envstring ,則會傳回零長度字串 (“) 。 否則, Environ 會 傳回指派給指定 之 envstring 的文字;也就是說,該環境變數的環境字串數據表中等號 (=) 下方的文字。

如果您指定 數位,則會傳回在環境字串數據表中佔用該數值位置的字串。 在此情況下, Environ 會 傳回所有文字,包括 envstring。 如果指定位置中沒有環境字串, Environ 會 傳回零長度字串。

範例

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

此範例使用 Environ 函數來提供環境字串數據表中 PATH 語句的輸入編號和長度。 無法在 Macintosh 上使用。

Dim EnvString, Indx, Msg, PathLen    ' Declare variables.
Indx = 1 ' Initialize index to 1.
Do
' Get environment variable.
EnvString = Environ(Indx)
' Check PATH entry.
If Left(EnvString, 5) = "PATH=" Then
' Get length.
PathLen = Len(Environ("PATH"))
Msg = "PATH entry = " & Indx & " and length = " _
& PathLen
Exit Do
Else
' Not PATH entry, so increment.
Indx = Indx + 1
End If
Loop Until EnvString = ""
If PathLen > 0 Then
' Display message.
MsgBox Msg
Else
MsgBox "No PATH environment variable exists."
End If

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!

×