Excel电子邮件在发送前挂起Outlook-错误处理?
我正在使用宏发送Excel工作簿,如下所示。我使用一个空白的电子邮件地址,以便在Outlook中显示电子邮件,并允许用户输入电子邮件地址。但是,除非电子邮件已发送或未发送即关闭,否则Excel将不允许用户在Outlook中执行任何其他操作,甚至不允许用户打开附件进行检查。在处理完电子邮件之前,它也不会关闭文件,因此它被困在这个循环中。我怎样才能避开这件事Excel电子邮件在发送前挂起Outlook-错误处理?,excel,vba,email,excel-2007,Excel,Vba,Email,Excel 2007,我正在使用宏发送Excel工作簿,如下所示。我使用一个空白的电子邮件地址,以便在Outlook中显示电子邮件,并允许用户输入电子邮件地址。但是,除非电子邮件已发送或未发送即关闭,否则Excel将不允许用户在Outlook中执行任何其他操作,甚至不允许用户打开附件进行检查。在处理完电子邮件之前,它也不会关闭文件,因此它被困在这个循环中。我怎样才能避开这件事 TempFilePath = Environ$("temp") & "\" TempFileName = "The File Name
TempFilePath = Environ$("temp") & "\"
TempFileName = "The File Name"
FileExtStr = ".xlsx"
With TheWorkbook
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
For I = 1 To 3
.SendMail "", _
"This is the Subject line"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close SaveChanges:=False
End With
而不是.SendMail为什么不使用Outlook进行后期绑定?这样,Excel就不必等待操作完成了
看这个例子
Option Explicit
Sub Sample()
Dim OutApp As Object
Dim OutMail As Object
Dim i As Long
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With ThisWorkbook
'
'~~> Do Something
'
For i = 1 To 3
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Subject = "This is the Subject line"
.Body = "Hello World"
.Attachments.Add TempFilePath & TempFileName & FileExtStr
'~~> Show the email
.Display
End With
Next i
End With
End Sub
而不是.SendMail为什么不使用Outlook进行后期绑定?这样,Excel就不必等待操作完成了
看这个例子
Option Explicit
Sub Sample()
Dim OutApp As Object
Dim OutMail As Object
Dim i As Long
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With ThisWorkbook
'
'~~> Do Something
'
For i = 1 To 3
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Subject = "This is the Subject line"
.Body = "Hello World"
.Attachments.Add TempFilePath & TempFileName & FileExtStr
'~~> Show the email
.Display
End With
Next i
End With
End Sub
为什么I=1到3?为什么I=1到3?感谢这很好,我只需要添加行.Attachments.add TempFilePath&TempFileName&FileExtStr。我有一行代码在发送文件后就删除了该文件,但我想这需要Excel等待电子邮件发送,并且电子邮件发件人可以简单地关闭该文件。感谢这一操作,我只需添加该行。Attachments.add TempFilePath&TempFileName&FileExtStr。我有一行在杀死文件一旦发送,但我想这将需要Excel等待,直到电子邮件发送,电子邮件发送者可以简单地关闭该文件。