Skip to main content

如何在Outlook中回覆或轉寄時為多個郵件帳號添加不同的簽名檔?

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

從教程: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中的不同帳號設置不同的簽名,但您是否嘗試過為回覆和轉寄應用不同的簽名呢?這意味著,當您回覆郵件時,插入signature1;當您轉寄郵件時,應用signature2。您如何在Outlook中解決這個問題呢?