Subプロシージャを書きます

Sub プロシージャは、SubEnd Subに囲まれた一連の Visual Basic のステートメントで、アクションは実行しますが値は返しません。 Sub プロシージャは、呼び出しプロシージャによって渡される定数変数などの引数を取ることができます。 Sub プロシージャに引数がない場合は、Sub ステートメントに一組の空の丸括弧を含める必要があります。

以下の Sub プロシージャには、各行を説明するコメントがあります。

' Declares a procedure named GetInfo 
' This Sub procedure takes no arguments 
Sub GetInfo() 
' Declares a string variable named answer 
Dim answer As String 
' Assigns the return value of the InputBox function to answer 
answer = InputBox(Prompt:="What is your name?") 
 ' Conditional If...Then...Else statement 
 If answer = Empty Then 
 ' Calls the MsgBox function 
 MsgBox Prompt:="You did not enter a name." 
 Else 
 ' MsgBox function concatenated with the variable answer 
 MsgBox Prompt:="Your name is " & answer 
 ' Ends the If...Then...Else statement 
 End If 
' Ends the Sub procedure 
End Sub

関連項目

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。