Microsoft KB Archive/241421

= XL98: SendMail Method Returns Run-time Error 1004 =

Article ID: 241421

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. 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:="" 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  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

