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.

執行物件的方法,或是設定或傳回 物件的屬性。

語法

CallByName ( 對象 procnamecalltype [, args () ])

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

引數

描述

物件

必要。 Variant (Object) 。 執行函數之物件的名稱。

procname

必要。 Variant (String) 。 包含物件屬性或方法名稱的字串表達式。

calltype

必要。 常數。 代表所稱程序類型的 vbCallType 常數。

args ()

選擇性。 Variant ( 列) 。


註解

CallByName 函數是用來取得或設定屬性,或是使用字串名稱在運行時間叫用方法。

在下列範例中,第一行使用 CallByName 來設定文本框的 MousePointer 屬性,第二行會取得 MousePointer 屬性的值,而第三行則會叫用 [移動 ] 方法來移動文本框:

CallByName Text1, "MousePointer", vbLet, vbCrosshair
Result = CallByName (Text1, "MousePointer", vbGet)
CallByName Text1, "Move", vbMethod, 100, 100

範例

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

此範例使用 CallByName 函數來叫用命令按鈕的 [移動 ] 方法。

此範例也會使用含有按鈕 (Command1) 的表單 (Form1) ,以及 (Label1) 標籤。 載入表單時,標籤的 Caption 屬性會設定為叫用方法的名稱,在此情況下為「移動」。 當您按鍵時, CallByName 函數會叫用變更按鈕位置的方法。

Option Explicit
Private Sub Form_Load()
Label1.Caption = "Move"' Name of Move method.
End Sub
Private Sub Command1_Click()
If Command1.Left <> 0 Then
CallByName Command1, Label1.Caption, vbMethod, 0, 0
Else
CallByName Command1, Label1.Caption, vbMethod, 500, 500
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!

×