运行时错误“ 438”对象不支持此属性或方法(发送自动电子邮件)

时间:2019-08-26 17:38:16

标签: excel vba excel-2016

单击表格中的按钮后,我试图在Outlook中将表格作为表格发送。我尝试编写代码以将其用作快照,但它确实有效,但这给我带来了很大的麻烦,同时使用超级查询从发送的电子邮件中编译日期。.我发现必须在体内放置表格,不是快照。

由于我是VBA的新用户,我似乎无法弄清楚问题出在哪里。

   Private Sub CommandButton2_Click()



Dim outlook As Object
Dim newEmail As Object
Dim sh As Worksheet

Set sh = ThisWorkbook.Sheets("FX Request Form")

Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(olMailItem)


With newEmail

.to = "belsawy@banquemisr.com"
.CC = ""
.bcc = ""
.Subject = sh.Range("C9").Value
.Body = ""


Dim xInspect As Object
Dim pageEditor As Object


Set xInspect = newEmail.GetInspector
Set pageEditor = xInspect.WordEditor

sh.Range("B2:C21").Copy

pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.Paste

.Send

Set oageEditor = Nothing
Set xInspect = Nothing

End With

Set newEmail = Nothing
Set outlook = Nothing

MsgBox "Your Request Has Been Sent To The Concerned Departments,Thank You"

End Sub

2 个答案:

答案 0 :(得分:0)

我和你有同样的问题。

您必须在“将xInspect作为对象添加”之前添加“ .Display”。

答案 1 :(得分:0)

在确保启用Outlook参考之后,我认为您遇到了一些一般性问题。

对于您的代码,您需要确定尺寸,以使其:

Private newEmail As Outlook.MailItem, outlook As Outlook.Application

Set outlook = CreateObject("Outlook.Application") 'YOU SPELLED THIS WRONG (forgot the T in outlook)
Set newEmail = outlook.CreateItem(olMailItem)

从那里开始,您的代码似乎应该合适。

您真正需要做的是将Option Explicit放在所有子例程之外的模块顶部,以确保您可以看到在哪里使用了“新变量”。