Microsoft Office Tutorials and References
In Depth Information
An Introductory VBA Function Example
Without further ado, I'll show you a simple VBA Function procedure. This function, named USER, does not ac-
cept any arguments. When used in a worksheet formula, this function simply displays the user's name in upper-
case characters. To create this function, follow these steps:
1. Start with a new workbook.
This is not really necessary, but keep it simple for right now.
2. Press Alt+F11 to activate the VB Editor.
3. Click your workbook's name in the Project window.
If the Project window is not visible, press Ctrl+R to display it.
4. Choose Insert ⇒ Module to add a VBA module to the project.
5. Type the following code in the code window:
‘ Returns the user's name
USER = Application.UserName
USER = UCase(USER)
Figure 24-1 shows how the function looks in a code window.
To try out the USER function, activate Excel (press Alt+F11) and enter the following formula into any cell in