Excel中Sendmail很简单,为什么在Word中就不能够直接通过参数指定收件人和主题呢?真心麻烦。
我想把当前Word文件作为附件发给收件人,有什么办法可以实现么?
VBA ActiveDocument.SendMail为什么不能够像Excel中一样带参数
答案:1 悬赏:0 手机版
解决时间 2021-03-07 01:30
- 提问者网友:你给我的爱
- 2021-03-06 09:18
最佳答案
- 五星知识达人网友:西岸风
- 2021-03-06 10:28
有问题追问我,运行code之前添加outlook的引用
Sub WordSendMail()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "test@sina.com"
.CC = "test@sina.com"
.Subject = "test"
.Body = ActiveDocument.Content
.Attachments.Add ActiveDocument.FullName
.Display
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
Sub WordSendMail()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "test@sina.com"
.CC = "test@sina.com"
.Subject = "test"
.Body = ActiveDocument.Content
.Attachments.Add ActiveDocument.FullName
.Display
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯