Home > Net >  Choose Reply Signature
Choose Reply Signature

Time:01-05

I have manually created a signature in outlook with name “Microsoft”.
I need to change Reply Signature to cited one.
I have installed Redemption and used the below code ,But I got Type Mismatch at this line Account.ReplySignature = "Microsoft"

Sub Change_Signature()
 
    Dim Account As Variant
    Dim Session As Object
   Set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
     Set Account = Session.Accounts.GetOrder(2).Item(1)   'First mail account
       Account.ReplySignature = "Microsoft"
       Account.Save
End Sub

As always, Thanks for all help.

CodePudding user response:

Please, try the next way:

  1. Account.ReplySignature is an object! So, it must be set, it cannot be a string (Signature.name)...

  2. In order to benefit of VBA Intellisense in the discussed case, I would like to suggest you to firstly set a reference to 'Redemption Outlook and MAPI Com library'. Since you try using Redemption you certainly registered the Com object...

  3. Declare variables in a way to see what properties/methods do they expose:

  Dim Account As RDOAccount, Session As RDOSession, Signature As RDOSignature
  1. Use the next function able to return a session signature object by its name:
Function setSignature(strSign As String, Account As RDOAccount) As Redemption.RDOSignature
    Dim Signature As RDOSignature
    For Each Signature In Account.Session.Signatures
        If Signature.Name = strSign Then
            Set setSignature = Signature: Exit Function
        End If
     Next
End Function
  1. Use the next adapted code:
Sub Change_Signature()
    Dim Account As RDOAccount, Session As RDOSession, Signature As RDOSignature
    Const signName As String = "IV_Signature"
    
    Set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      Set Account = Session.Accounts.GetOrder(2).Item(1)   'First mail account
      Set Signature = setSignature(signName, Account)
      If Account.ReplySignature Is Nothing Then
            Set Account.ReplySignature = Signature
            Account.Save: MsgBox "Changed to """ & signName & """!"
     Else
            If Signature.Name <> Account.ReplySignature.Name Then
                    Set Account.ReplySignature = Signature
                    Account.Save: MsgBox "Changed to """ & signName & """!"
            Else
                    MsgBox "This account already usess signature """ & signName & """..."
            End If
     End If
End Sub

The above code can be adapted to use late binding, but you can only use it, without being able to see the rest of used objects properties, methods in case of future needs/developments... Then, early binding is always faster then late. In this very case this aspect does not matter too much, but it is good to have it in your mind, I think.

Of course, there are ways to improve it, for instance to determine if used signature name was misspelled... In such a case Signature will be Nothing, so If Signature is Nothing then MsgBox "Wrong signature string...": Exit Sub.

  • Related