Microsoft Office Tutorials and References
In Depth Information
Introducing the Visual Basic Editor
Using the macro recorder can help you to identify various properties that you can use in your
custom functions. For example, turn on the macro recorder to record your actions while you
change the username. Follow these steps in Excel:
1. Choose Developer
Record Macro.
2. In the Record Macro dialog box, accept the default settings and click OK to begin
The Record Macro button’s caption changes to Stop Recording.
3. Choose File
Options and click the General tab.
4. Under the Personalize Your Copy of Microsoft Office heading, change the name in the
User Name box.
5. Click OK to close the Excel Options dialog box.
6. Choose Developer
Stop Recording.
7. Press Alt+F11 to activate the VB Editor.
8. In the Project window, select the project that corresponds to your workbook.
9. Double-click the VBA module that contains your recorded code.
Generally, this will be the module with the highest number (for example, Module3).
You’ll find a VBA procedure that looks something like this:
Sub Macro1()
‘ Macro1 Macro
Application.UserName = “Robert Smith”
End Sub
Note that this is a Sub procedure, not a Function procedure. In other words, you can’t use this
procedure in a worksheet formula. If you examine the code, however, you’ll see a reference to the
UserName property. You can use this information when creating a Function procedure. For
example, the following Function procedure uses the UserName property. This function, when
used in a worksheet formula, returns the name of the user.
Function USER()
USER = Application.UserName
End Function
Search JabSto ::

Custom Search