Leedo
Leedo

Reputation: 611

How can I temporarily set the signature of (Replies/Forwards) to None?

Is it possible to temporarily set the signature of (Replies/Forwards) to None using VBA or Windows Registry setting?

I mean at beginning of the Sub objInboxItems_ItemAdd to set the signature of (Replies/Forwards) to None and at end revert it to my previous signature.

Enter image description here

Public WithEvents objInbox As Outlook.Folder
Public WithEvents objInboxItems As Outlook.Items

Private Sub Application_Startup()
    Set objInbox = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
    Set objInboxItems = objInbox.Items
End Sub

Private Sub objInboxItems_ItemAdd(ByVal item As Object)
    Dim objMail As Outlook.MailItem
    Dim objForward As Outlook.MailItem

    If Not TypeOf item Is MailItem Then Exit Sub

    Set objMail = item
    Set objForward = objMail.Forward

    'Customize the forward subject, body and recipients'
    With objForward
        .Recipients.Add ("[email protected]")
        .Recipients.ResolveAll
        .Send
    End With
End Sub

Upvotes: 0

Views: 339

Answers (3)

Leedo
Leedo

Reputation: 611

The courtesy of this answer by Dmitry Streblechenko.

I just added a workaround (API Message Box) to his code to make it fully workable.

First, you need to download Redemption Link and install it , either by run install.exe or register its Dll.

This part of code will be put on ThisOutlookSession module:

    Dim Account As Variant
    Static Signature As Variant

    Dim Session As Object: Set Session = CreateObject("Redemption.RDOSession")  'Late Binding
   'Dim Session As New Redemption.RDOSession                                    'Early Binding

    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
     Set Account = Session.Accounts.GetOrder(2).Item(1)     'First mail account
      Set Signature = Account.ReplySignature
       Account.ReplySignature = Nothing
       Account.Save

     Call MsgBoxTimeout(0, "This MsgBox will close by itself", "", vbInformation, 0, 1)
'_____________

     'Do other code here
'_____________

      Account.ReplySignature = Signature      'Restore Reply_Forward Signature
      Account.Save

Note: you have to put this API declaration on a separate module other than ThisOutlookSession

Public Declare Function MsgBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" ( _
            ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, _
            ByVal wType As VbMsgBoxStyle, ByVal wlange As Long, ByVal dwTimeout As Long) As Long

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66341

On the Extended MAPI level (C++ or Delphi), you can use IOlkAccountManager interface to set the new/reply signatures. They are stored as properties on the IOlkAccount object. You can see them in OutlookSpy (I am its author) if you click IOlkAccountManager button and the double click on the corresponding account:

Enter image description here

If Extended MAPI is not an option, you can use Redemption (any language; I am also its author). It exposes New and Reply signatures on the RDOAccount object:

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account
if Not (Account Is Nothing) Then
  set Signature = Account.ReplySignature
  Account.ReplySignature = Nothing
  Account.Save
  ' do something
  ' then restore the reply signature
  Account.ReplySignature = Signature
  Account.Save
End If

Upvotes: 2

FaneDuru
FaneDuru

Reputation: 42256

As I said in my comment, the next suggested solution delete signature, if exists...

Please, copy the next sub in the project dealing with Outlook forward automation:

Sub ClearSignature(oMail As Object)
        Dim objWdEd As Object, oBjBookM As Object
        Set objWdEd = oMail.GetInspector.WordEditor
        On Error GoTo NoSignature
        Set oBjBookM = objWdEd.Bookmarks("_MailAutoSig")
          oBjBookM.Range.Delete
          Exit Sub
        
NoSignature:
        Debug.Print "No Any Signature found..." 'it may be commented...
End Sub

The following part of your code should be adapted as:

 'your existing code...
       With objForward
            .Recipients.Add ("[email protected]")
            .Recipients.ResolveAll
            'inserted lines _______________________
              .Display 'to load signature, if any...
              ClearSignature objForward  'to clear the signature (if any)
             '_____________________________________
            .Send
        End With
 'your existing code

The suggested solution has the disadvantage if screen flickering (display it for short time, before sending), in case of mass forwarding...

Upvotes: 1

Related Questions