【问题标题】:Macro doesn't show open mail宏不显示打开的邮件
【发布时间】:2020-06-25 17:08:31
【问题描述】:

以下是我发送电子邮件的宏,但它不会打开新电子邮件。

此宏在 Outlook 规则中。

你有什么想法吗?

  Sub sendemail()

  Dim ns As NameSpace
 'Dim newMail As Outlook.MailItem

Set ns = GetNamespace("MAPI")
 Dim newMail As MailItem
Set newMail = Application.CreateItem()

With newMail
  .To = "aaa@bbb" <--adress to whitch I want to send an email
  .Subject = "test"
  .Display
 End With
Set newMail = Nothing

  End Sub

【问题讨论】:

标签: vba outlook


【解决方案1】:

首先你需要添加outlook参考:

你去吧:

然后:

Sub sendemail()

  Dim outlook As New outlook.Application
 Dim newMail As outlook.MailItem

    Set newMail = outlook.CreateItem(olMailItem)


    With newMail
      .To = "email@address.com" ' <--adress to whitch I want to send an email
      .Subject = "test from Steph"
      .Display
      .Send
     End With
    Set newMail = Nothing
    outlook.Quit
    Set outlook = Nothing

  End Sub

【讨论】:

  • 我在宏下成功运行但是当我尝试在 Outlook 中作为规则运行它时它什么也没做 Sub sendemail() Dim newMail As outlook.MailItem Set newMail = Application.CreateItem(olMailItem) With newMail .To = "aaa@aaa.com" .Subject = "test" .Send End With Set newMail = Nothing End Sub
  • 我更新了我的答案。问题可能需要添加outlook参考。告诉我
【解决方案2】:

参数必须是 MailItemMeetingItem 子例程才能在 Outlook 规则向导中使用。

试试这个。

Option Explicit
Sub SendEmail(NewMail As Outlook.MailItem)

    Set NewMail = Application.CreateItem(olMailItem)

    With NewMail
        .To = "aaa@bbb"  '<--adress to whitch I want to send an email
        .Subject = "test"
        .Display
    End With

    Set NewMail = Nothing
End Sub

【讨论】:

    【解决方案3】:

    您没有指定要创建的项目。见这里:

    Private Sub SendEmail(ByVal workcenter As Integer, ByVal time As Date)
        Dim objApp As Object
        Dim objEmail As Object
        Set objApp = CreateObject("Outlook.Application")
        Set objEmail = CreateObject("Outlook.MailItem")
        With objEmail
            .To = "emailexampe@website.com"
            .Subject = "Multiple Shop Orders run for line " & workcenter & " at " & time
            .body = "TEST"
            .display
        End With
        Set objEmail = Nothing
        Set objApp = Nothing
    
    End Sub
    

    来源:http://www.vbforums.com/showthread.php?536558-RESOLVED-Outlook-late-binding

    这个版本也使用后期绑定,所以你不需要任何额外的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多