OL97: VBScript Example Returns the Current User Name

Last reviewed: February 27, 1998
Article ID: Q167137
The information in this article applies to:
  • Microsoft Outlook 97

SUMMARY

This article describes how to use Visual Basic Scripting Edition (VBScript) with Microsoft Outlook 97 to return the current user name.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

The following example uses a message form, one command button, and a message box to return the current user's name.

Creating the Form and CommandButton Control

  1. From the Inbox, on the File menu, point to New and click Mail message.

  2. On the message form Tools menu, click "Design Outlook Form" to enter the form design mode.

  3. Click the form (P.2) tab, and on the Form menu, click "Display This Page."

  4. On the Form menu, click "Control Toolbox." Drag the Command Button to the form.

Creating the VBScript to Return the User Name

  1. On the Form menu, click "View Code" to open the VBScript editor.

    NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in VBScript.

  2. Type the following code into the editor window:

       'Sub routine that runs when you click CommandButton1
       Sub CommandButton1_Click()
          'Message box that returns the current user's name
          MsgBox "The current user is " & _
             Application.GetNameSpace("MAPI").CurrentUser
       End Sub
    
    

  3. On the Script Editor File menu, click Close.

  4. On the form Tools menu, click "Design Outlook Form" to exit the form design mode.

If you click CommandButton1, you will see a message box that contains the current user's name.

REFERENCES

For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q166368
   Title     : OL97: How to Get Help Programming with Outlook

   Article-ID: Q170783
   Title     : OL97: Q&A: Questions about Customizing or
               Programming Outlook


Additional query words: OutSol OutSol97

Version : 97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.