How to Call a Function in VBA
Visual Basic for Applications (VBA) is Microsoft's event-driven programming language, which is associated with Visual Basic 6 and its Integrated Development Environment (IDE). VBA is widely used within many of Microsoft's products and platforms, including Microsoft Office. The VBA language makes heavy use of functions, which are blocks of programming code and commands a programmer writes within VBA.
Instructions
-
-
1
Open Microsoft Word.
-
2
Click "Tools," "Macro" and click on "Visual Basic." You are now in the Visual Basic programming environment.
-
-
3
Go to the top menu bar and click on "Insert" then click on "Module."
-
4
Write the following code within the code Module:
Function mymessagebox()
MsgBox "Here is an example of how to call a function"
End Function
-
5
Go to the top menu bar and click on "Insert," then click on "UserForm."
-
6
Double-click the Userform and type the name of the function: "mymessagebox." In the forms default click "Event." Your programming code should look like this:
Private Sub UserForm_Click()
call mymessagebox
End Sub
-
7
Press "F5" on your keyboard to run the program. This will run the program and display a form dialog Window.
-
8
Click on the Userform dialog Window. You should see a message box pop up in-front of the Userform Window with the words "Here is an example of how to call a function."
-
1