XL98: SendMail Method Returns Run-time Error 1004

ID: Q241421


SYMPTOMS

When you run a macro that uses the SendMail method, you may receive the following error message:

Run-time error '1004':

Method 'SendMail' of object '_Workbook' failed


CAUSE

The SendMail method only works with MAPI mail clients, such as Starnine Mail. In these clients, the MailSystem property returns a value of 1.


RESOLUTION

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 professionals 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 a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
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/overview/overview.asp
The following sample macro verifies if the mail client that you are using is a MAPI client. Then, based on the result, the macro either uses the SendMail method or an alternative method using the Mail Recipient CommandBar control.

Sub Check_Mail()
Select Case Application.MailSystem
Case xlMAPI
    ThisWorkbook.SendMail Recipients:="<valid e-mail address>"
    
Case xlNoMailSystem
    MsgBox "no mail client"

Case Else
    Application.CommandBars("worksheet menu bar") _
    .Controls("File").Controls("Send To").Controls("Mail Recipient...").Execute
    
End Select

End Sub 
NOTE: In the above code, replace <valid e-mail address> with the e-mail address of a person to whom you can usually send an e-mail message via your e-mail client.

When you run the Check_Mail macro, it sends your workbook to the specified person if you are using a MAPI e-mail client. If you are not using a MAPI e-mail client, your e-mail client is started, but you have to type the person's e-mail address in the new message that is created.


MORE INFORMATION

Depending on your e-mail client, the MailSystem property returns one of the following constants:


   Constant          Value
   -----------------------

   xlNoMailSystem      0
   xlMAPI              1
   xlPowerTalk         2 


REFERENCES

For additional information about how to run sample code, click the article number below to view the article in the Microsoft Knowledge Base:

Q181058 OFF98: How to Run Sample Code from Knowledge Base Articles

Additional query words: vba xl98 email e-mail

Keywords : kbdta OffVBA
Version :
Platform :
Issue type : kbprb


Last Reviewed: November 5, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.