Microsoft KB Archive/169355

From BetaArchive Wiki

Article ID: 169355

Article Last Modified on 11/8/2000


  • Microsoft Excel 97 Standard Edition

This article was previously published under Q169355


This article describes the correct way to use the Visual Basic for Applications MailLogon method in Microsoft Excel 97. It also lists possible problems that you may encounter when you use this method to establish a mail session in Microsoft Excel 97.


Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Using the MailLogon Method

To properly use the MailLogon method, specify a valid Name argument. For example, if a mail profile called "John Q. Public" exists on your computer, the following line of code is valid:

   Application.MailLogon "John Q. Public"

Using the MailLogon Method Improperly

If you do not specify a Name argument in the MailLogon command, for example, if you use the following line of code


the Choose Profile dialog box may appear and request that you choose a mail profile. This may be a problem if you want to run the macro without supervision; if this is the case, specify a valid Name argument.

If the MailLogon command specifies an invalid Name argument, for example, if you use the following line of code

   Application.MailLogon "N. O. Body"

you may receive the following error message:

Microsoft Exchange The profile name is not valid. Enter a valid profile name.

When you click OK, the Choose Profile dialog box is displayed.

If you click Cancel in either the Choose Profile dialog box or the "Profile name is not valid" error message dialog box, you receive the following error message

Run-time error '1004': Method 'MailLogon' of object '_Application' failed

and the macro halts.

Using the Password and DownloadNewMail Arguments

These arguments are optional; you only need to include them if your mail is protected by a password or if you want to download new mail messages immediately. Note that the Password argument is ignored if you are using Microsoft Exchange or Microsoft Outlook 97.

Help Information for the MailLogon Method

The Microsoft Excel Visual Basic Help topic for the MailLogon method states the following:

Name Optional Variant. The mail account name of Microsoft Exchange profile name. If this argument is omitted, the default mail account name is used.

This statement is not entirely correct. If you omit the Name argument from the MailLogon method, the Choose Profile dialog box may appear and request that you choose a mail profile.

For an example of the correct way to use the MailLogon method, see the MailLogon Method example; the Name, Password, and DownloadNewMail arguments are all present and valid.

Additional query words: XL97 mapi microsoft mail

Keywords: kberrmsg kbprb KB169355