请问: 如何在Excel中自动用Outlook发送该文件给其他人? ( 急! )

我在Excel中可以用下面的语句调用出Outlook发送该文件,但发送方的地址却没有,还要我手工去填写。如果我要做到运行该宏的时候自动给某人(比如:abc@abc.com),那么应该怎么写呢?
Sub MailSending()
Application.Dialogs(xlDialogSendMail).Show
End Sub
[198 byte] By [xuel-山顶洞人] at [2007-12-16]
# 1
ActiveWorkbook.SendMail Recipients:="address"
sxfwang at 2007-10-15 > top of Msdn China Tech,其他开发语言,Office开发/VBA...
# 2
ActiveWorkbook.SendMail("abc@abc.com")
# 3
expression.SendMail(Recipients, Subject, ReturnReceipt)
yangzhaoyu-老妖 at 2007-10-15 > top of Msdn China Tech,其他开发语言,Office开发/VBA...
# 4
我直接用 ActiveWorkbook.SendMail("abc@abc.com")
结果出现选择框,如果选择是就可以发送,但为什么选择No就会出错?
xuel-山顶洞人 at 2007-10-15 > top of Msdn China Tech,其他开发语言,Office开发/VBA...
# 5
感谢您使用微软的产品。

您提出的问题和Outlook的安全特性有关。

为了不出现这个警告提示而直接通过Outlook从其他Office应用程序,如Excel来发送邮件,

(一)、如果您采用Exchange作为您的邮件服务器,您可以借助下面的用Outlook E-mail Security Administrator Package(Admpack.exe)定制自己的Outlook的安全属性的方法来解决:

The Outlook E-mail Security Administrator Package (Admpack.exe) can be installed from the Microsoft Office XP Enterprise CD located in the following folder: \ORK\FILES\PFILES\ORKTOOLS\ORK10\TOOLS\ADMPACK

Customizing the Outlook E-mail Security Update
====================================

Before you begin to modify the security settings, you must create a public folder named "Outlook 10 Security Settings" on your Exchange Server. The administrator must create this folder, using that exact name, in the root folder of the Public Folder tree. You must set the folder Access Control Lists (ACL) so all users can read all items in the folder.

1. On a computer running Outlook, open OutlookSecurity.oft from the file system.

2. When asked to select a folder, select the Outlook 10 Security Settings public folder that you created on Exchange Server. The template will then open in Compose mode.

3. On the Tools menu of the template, point to Forms, and then click Publish Form. (The folder selected should be your current folder, Outlook Security Settings.)

4. In the Form Name box, type "Outlook Security Form".

5. Click the Publish button. The security template is now published in the Security Settings folder.

6. Close the form, and when prompted to save changes, click No.

7. In the Folder List, right-click the Outlook Security Settings folder, and then click Properties on the shortcut menu.

8. In the When posting to this folder, use list, click Outlook Security Form, and then click OK.

9. Click the New button to open up a new security template.

10. Create either a default security setting or custom settings for a specific set of users.

11. Modify the settings in the Programmatic Settings table and Outlook Security Settings table.

Modify the Registry of client
=====================
IMPORTANT: This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:
Q256986 Description of the Microsoft Windows Registry

1. Start the registry editor and expand the following sub key:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Security

2. From the Edit menu, choose New, then click DWORD value to add a new registry key. The value name for the key must be CheckAdminSettings.

3. Set the new key value.

No key: means that Outlook uses default administrative settings.

Set to 0: means that Outlook uses default administrative settings.

Set to 1: Outlook looks for custom administrative settings in the Outlook Security Settings folder.

Set to 2: Outlook looks for custom administrative settings in the Outlook 10 Security Settings folder.

Key set to anything else: means Outlook uses default administrative settings.

Please set the value of the key to 2.

For more information, please refer to the following KB article:
Q290499 OL2002: Administrator Info About E-Mail Security Features
(http://support.microsoft.com/support/kb/articles/q290/4/99.asp)

(二)如果您不采用Exchange作为自己的mail server的话,您可以借助CDO编程来不显示这个警告信息而直接调用Outlook发信。具体可以参照如下:

Because if we are developing a Windows service that uses CDO, security prompts will not be generated since CDO detects that it is running in a service and therefore does not display security prompts.

You can refer to the following sample code to resolve the issue:
'This also appears as the "QuickStart" example in "Overview"
Function QuickStart()
Dim objSession As Object ' or Dim objSession As MAPI.Session
Dim objMessage As Object ' or Dim objMessage As Message
Dim objOneRecip As Object ' or Dim objOneRecip As Recipient

On Error GoTo error_olemsg

' create a session then log on, supplying username and password
Set objSession = CreateObject("MAPI.Session")
' change the parameters to valid values for your configuration
objSession.Logon 'profileName:="Jane Doe", _
'profilePassword:="my_pword"

' create a message and fill in its properties
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Sample Message"
objMessage.Text = "This is some sample message text."

' create the recipient
Set objOneRecip = objMessage.Recipients.Add
objOneRecip.Name = "John Doe"
objOneRecip.Type = CdoTo
objOneRecip.Resolve

' send the message and log off
objMessage.Update
objMessage.Send showDialog:=False
MsgBox "The message has been sent"
objSession.Logoff
Exit Function

error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Resume Next

End Function
For more information in detail, please refer to the following article in the MSDN:
Platform SDK: CDO 1.2.1
Creating and Sending a Message
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_creating_and_sending_a_message.asp )

For additional information about how to avoid the security prompts, please view the article in the Microsoft Knowledge Base:
Q290500 OL2002: Developer Information About E-Mail Security Features Using CDO 1.21s in a Service
(http://support.microsoft.com/default.aspx?scid=kb;en-us;Q290500 )

For additional information about CDO 1.21s Security Features, please refer to the article in the Microsoft Knowledge Base:
Q295302 OL2002: Summary of CDO 1.21s E-mail Security Features
(http://support.microsoft.com/default.aspx?scid=kb;en-us;Q295302 )

For more information about the CDO object model, see the following article on the Microsoft Web site:
(http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/cdo/_olemsg_overview_of_cdo.htm

希望上述信息对您有所帮助。

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。

为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。

davwang-[微软]蜘蛛人 at 2007-10-15 > top of Msdn China Tech,其他开发语言,Office开发/VBA...
# 6
这个问题没有上面说的那么复杂吧,而且最上面几位说的也不是用Outlook来发信。我自己写了段代码并实验成功,你看看吧:

Sub xlSendFileThroughOutlook()
Dim fileName As String
Dim olApp As Object
Dim myMail As Object

fileName = ActiveWorkbook.FullName '得到当前Excel文件的名称、路径

On Error GoTo createError
Set olApp = CreateObject("Outlook.Application")
Set myMail = olApp.CreateItem(olMailItem)
With myMail
.To = "abc@abc.com"
.Subject = "Send you a file"
.Body = "Hi abc ..."
.AttachMents.Add (fileName) '添加附件
.Save '这句不要也可以
.Send '发送邮件
End With

olApp.Quit '退出Outlook
Set olApp = Nothing

Exit Sub
createError:
MsgBox "Unable to Create Outlook Object"

End Sub
# 7
感谢您使用微软的产品,也很高兴能和您进行相关的技术交流。

原始问题的提出者是想在Excel中调用Outlook直接把当前处理的文件作为邮件自动发送给其他人。实际上我们通过查找相应的技术文档可以知道,实现这一功能有很多种方法。

但是由于Outlook2000,Outlook XP中所包含的安全特性,所以当发信时会弹出警告信息对话框,如果选择No,将会报错;如果等待5-10秒钟,则Yes按钮变为可见,可以选择Yes,把信件发出。对于重复发送到同一地址的应用需求来说,这无疑是很烦琐不容易操作的。所以我上面的那篇文章主要是介绍如何屏蔽警告信息对话框,主要分为使用Exchange作为邮件服务器和不使用Exchange两种情况。

至于通过编程实现自动发信功能,您可以通过查找MSDN,Office Programming方面的相关文档以及上面我所提供的微软知识库的文章的链接,都能找到很多相关的信息和示例代码。但是很多情况下,大家都对那个告警信息对话框有些迷惑,所以我利用自己碰到的一些案例说明一下。

希望上述信息对您有帮助。

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。

为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
davwang-[微软]蜘蛛人 at 2007-10-15 > top of Msdn China Tech,其他开发语言,Office开发/VBA...