You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否编程设置Microsoft Outlook自动回复?如何用宏插入发件人姓名

Configuring Outlook Out-of-Office Auto-Reply with Dynamic Sender Name via VBA

Absolutely, you can pull this off using a VBA macro paired with an Outlook rule—since the native Out-of-Office (OOF) feature doesn’t support dynamic variables like the sender’s name, this custom solution will get the job done. Here’s a step-by-step guide to set it up:

Step 1: Enable the Developer Tab in Outlook

First, make sure you can access the tools needed to build macros:

  • Go to File > Options > Customize Ribbon
  • Check the box next to Developer in the right-hand pane, then click OK

Step 2: Create the VBA Macro

  1. Click the Developer tab, then select Visual Basic to open the VBA Editor.
  2. In the left-side Project Explorer, right-click your Outlook project (it’ll look like Project1 (Outlook VBA Project)), then choose Insert > Module.
  3. Paste the following code into the new module:
Sub AutoReplyWithSenderName(Item As Outlook.MailItem)
    Dim replyMail As Outlook.MailItem
    Dim senderName As String
    Dim oNS As Outlook.NameSpace
    Dim oMailbox As Outlook.Mailbox
    
    ' Optional: Only run if native Out-of-Office is enabled
    Set oNS = Application.GetNamespace("MAPI")
    Set oMailbox = oNS.GetDefaultFolder(olFolderInbox).Parent
    If Not oMailbox.OutOfOfficeEnabled Then
        Exit Sub ' Skip if OOF isn't turned on
    End If
    
    ' Grab the sender's display name
    senderName = Item.SenderName
    
    ' Create a reply message
    Set replyMail = Item.Reply
    
    ' Customize your auto-reply content (HTML for formatting)
    replyMail.HTMLBody = "<p>Dear " & senderName & ",</p>" & _
                         "<p>I will return on Feb 30th. For urgent matters, please contact Jane Doe at jane.doe@example.com.</p>" & _
                         replyMail.HTMLBody ' Keeps your existing email signature
    
    ' Set the reply subject (optional)
    replyMail.Subject = "RE: " & Item.Subject
    
    ' Send the auto-reply
    replyMail.Send
    
    ' Clean up unused objects
    Set replyMail = Nothing
    Set oMailbox = Nothing
    Set oNS = Nothing
End Sub

Quick Customization Tips:

  • Tweak the reply text in the HTMLBody line to match your needs (update return date, urgent contact info, etc.).
  • If you prefer plain text over formatted HTML, replace replyMail.HTMLBody with replyMail.Body and remove the <p> tags.

Now, set up a rule to trigger the macro automatically when you receive emails:

  1. Go to Home > Rules > Manage Rules & Alerts
  2. Click New Rule, select Apply rule on messages I receive, then click Next
  3. Pick any conditions you want (e.g., "only if my name is in the To or Cc box" to avoid replying to spam) and click Next
  4. Under What do you want to do with the message?, select run a script
  5. From the dropdown menu, choose the macro you created (AutoReplyWithSenderName) and click Next
  6. Add exceptions (like "except if from my team") if needed, then click Next
  7. Name your rule (e.g., "Dynamic OOF Auto-Reply"), check Turn on this rule, and click Finish

Important Notes:

  • Macro Security: You’ll need to enable macros in Outlook to use this. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros (or use digitally signed macros for better security).
  • Toggle Control: The macro includes a check to only run when your native OOF is enabled—so you can turn the dynamic auto-reply on/off just by toggling your regular OOF setting.

内容的提问来源于stack exchange,提问作者Carl Witthoft

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:42:41