跳至主要内容

如何在Outlook中回复或转发时为多个电子邮件帐户添加不同的签名?

Author: Amanda Li Last Modified: 2025-05-08

从教程:Outlook中的电子邮件签名,您应该知道如何在Outlook中创建签名。然而,在创建新签名后,如果您希望在回复或转发邮件时添加该签名,则必须通过在邮件窗口中选择“签名 > 已创建的签名”来手动添加已创建的签名。

当然,您可以通过点击“签名 > 签名”,并为特定电子邮件帐户选择一个签名(如下所示),让Outlook在您回复或转发新邮件时自动添加签名。

the steps of adding different signatures to multiple email accounts when reply or forward in Outlook

但是,如果您有许多电子邮件帐户,并希望批量为您的多个帐户添加不同的签名该怎么办呢?在本教程中,我将介绍一种VBA方法,帮助您轻松完成此任务。


在Outlook中回复或转发时为多个电子邮件帐户添加不同的签名

1. 在您的Outlook中,按 Alt + F11 键打开Microsoft Visual Basic for Applications窗口。

2. 在Microsoft Visual Basic for Applications窗口中,双击项目窗格中的ThisOutlookSession,并将以下VBA代码复制到ThisOutlookSession(代码)窗口中。见截图:

the steps of adding different signatures to multiple email accounts when reply or forward in Outlook

VBA代码:在Outlook中创建新邮件时为多个电子邮件帐户添加不同的签名 - ThisOutlookSession

Public WithEvents GInspectors As Inspectors
Public WithEvents GExplorer As Explorer

Private Sub Application_Startup()
  Set GInspectors = Application.Inspectors
  Set GExplorer = Application.ActiveExplorer
End Sub

Private Sub GExplorer_InlineResponse(ByVal Item As Object)
‘Update by ExtendOffice
Dim xMail As MailItem
On Error Resume Next
EndTimer
If Item.Class = olMail Then
  Set xMail = Item
  Set GInspector = Nothing
  Set GInspector = xMail.GetInspector
  StartTimer
End If
End Sub

Private Sub GInspectors_NewInspector(ByVal Inspector As Inspector)
  On Error Resume Next
  EndTimer
  Set GInspector = Nothing
  Set GInspector = Inspector
  StartTimer
End Sub

3. 在Microsoft Visual Basic for Applications窗口中,点击“插入 > 模块”。然后将以下VBA代码复制到模块窗口中。

the steps of adding different signatures to multiple email accounts when reply or forward in Outlook

VBA代码:在Outlook中回复或转发时为多个电子邮件帐户添加不同的签名 - 模块

Public Declare PtrSafe Function SetTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As Long
Public Declare PtrSafe Function KillTimer Lib "user32" (ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Public TimerID As Long
Public GInspector As Inspector

Sub StartTimer()
  On Error Resume Next
  TimerID = SetTimer(0&, 0&, 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
  On Error Resume Next
  KillTimer 0&, TimerID
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
  On Error Resume Next
  Call SetSignatureToAccount
  EndTimer
End Sub

Sub SetSignatureToAccount()
‘Update by ExtendOffice
Dim xMail As MailItem
Dim xSignatureFile, xSignaturePath As String
Dim xSubject As String
Dim xDoc As Document
Dim xAccount As Account
Dim xIsNew As Boolean
Dim xInspector As Inspector
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
On Error Resume Next
xSignaturePath = CreateObject("WScript.Shell").SpecialFolders(5) + "\Microsoft\Signatures\"
xSubject = GInspector.Caption
Set xDoc = GInspector.WordEditor
xIsNew = False
Set xMail = GInspector.CurrentItem
Select Case xMail.Parent.Parent
  Case "name1@example.com" 'Replace the email address in double quotes
    If VBA.InStr(xSubject, "RE: ") Then
      xSignatureFile = xSignaturePath & "Signature1.htm" 'Replace "Signature1" with your actual signature name that you will set as the signature when you reply to a message.
    ElseIf VBA.InStr(xSubject, "FW: ") Then
      xSignatureFile = xSignaturePath & "Signature2.htm" 'Replace "Signature2" with your actual signature name that you will set as the signature when you forward a message.
    Else
      xIsNew = True
      Exit Sub
    End If
  Case "name2@example.com" 'Replace the email address in double quotes
    If VBA.InStr(xSubject, "RE: ") Then
      xSignatureFile = xSignaturePath & "Signature3.htm" 'Replace "Signature3" with your actual signature name that you will set as the signature when you reply to a message.
    ElseIf VBA.InStr(xSubject, "FW: ") Then
      xSignatureFile = xSignaturePath & "Signature4.htm" 'Replace "Signature4" with your actual signature name that you will set as the signature when you forward a message.
    Else
      xIsNew = True
      Exit Sub
    End If
  'Add more Cases for more email accounts
End Select
If xIsNew = True Then
  With xDoc.Application.Selection
    .WholeStory
    .EndKey
    .InsertParagraphAfter
    .MoveDown Unit:=wdLine, Count:=1
    .InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
  End With
Else
  With xDoc.Application.Selection
    .MoveRight Unit:=wdCharacter, Count:=1
    .HomeKey Emptyparam, Emptyparam
    .InsertFile FileName:=xSignatureFile, Link:=False, Attachment:=False
  End With
End If
Set xDoc = Nothing
Set GInspector = Nothing
Set xMail = Nothing
End Sub
注意:
  • 1) 您应将第39行和第48行中的name1@example.comname2@example.com替换为您的实际电子邮件地址。
  • 2) 您应根据注释将第41行、第43行、第50行和第52行中的Signature替换为您的实际签名名称。
  • 3) 使用上述VBA代码,我们可以为两个电子邮件帐户添加签名。如果您有更多帐户,请用更多Case替换代码的第57行:
  • Case "name@example.com" If VBA.InStr(xSubject, "RE: ") = 1 Then xSignatureFile = xSignaturePath & "Signature1.htm" ElseIf VBA.InStr(xSubject, "FW: ") = 1 Then xSignatureFile = xSignaturePath & "Signature2.htm" Else xIsNew = True Exit Sub End If

4. 在Microsoft Visual Basic for Applications窗口中,点击“工具 > 引用”,勾选Microsoft Word 16.0 Object Library旁边的框,然后点击确定

the steps of adding different signatures to multiple email accounts when reply or forward in Outlook

5. 重新启动Outlook,并保存VBA代码。

6. 现在,当您使用已设置签名的电子邮件帐户回复或转发邮件时,相应的签名将自动添加。

注意:如果您发现在使用电子邮件帐户回复或转发邮件时添加了两个签名,请在邮件窗口中点击签名 > 签名。在选择默认签名部分,选择有两个签名的电子邮件帐户,并从回复/转发下拉列表中选择(无)

the steps of adding different signatures to multiple email accounts when reply or forward in Outlook

相关文章

如何在Outlook中导入或插入HTML签名?

例如,您从网站下载了一些HTML签名,并希望将它们导入到您的Outlook中。有什么简单的方法吗?本文将指导您逐步将HTML签名导入或插入到Outlook中。

如何在Outlook签名中插入背景颜色?

在Outlook的邮件中添加或删除背景颜色很容易。但是,如何在Outlook签名中插入或删除背景颜色呢?以下解决方法将帮助您解决这个问题:

如何在Outlook中创建新邮件时为多个电子邮件帐户添加不同的签名?

如果您希望Outlook在创建新邮件时自动添加签名,则需要通过点击“签名 > 签名”,并为特定电子邮件帐户选择一个签名(如下所示)来配置默认签名。但是,如果您有许多电子邮件帐户,并希望批量为您的多个帐户添加不同的签名该怎么办呢?在本教程中,我将介绍一种VBA方法,帮助您轻松完成此任务。

如何在Outlook中为回复和转发设置不同的签名?

通常,您可以在Outlook中为不同帐户设置不同的签名,但您是否尝试过为回复和转发应用不同的签名呢?这意味着,当您回复邮件时,插入签名1;当您转发邮件时,应用签名2。如何在Outlook中解决这个任务呢?