0

I am writing macro that will set a signature after choosing the From field or for example clicking reply. My problem is that I don't know how to get the From field value. I know how to set this field.

Function GetBoiler(ByVal sFile As String) As String
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function

Function GetSignature(Mailbox As String) As String
   Dim Signature As String
   Dim SigStringPL As String
   Dim SigStringUK As String
    SigStringPL = Environ("appdata") & _
                  "\Microsoft\Signatures\Poland.htm"

    SigStringUK = Environ("appdata") & _
                  "\Microsoft\Signatures\United Kingdom.htm"

    If Mailbox = "poland@poland.pl" Then
        If Dir(SigStringPL) <> "" Then
            GetSignature = GetBoiler(SigStringPL)
        Else
            GetSignature = ""
        End If
    Else
        If Dir(SigStringUK) <> "" Then
            GetSignature = GetBoiler(SigStringUK)
        Else
            GetSignature = ""
        End If
    End If
End Function


Sub Mail_Outlook_With_Signature_Plain()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2010
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "content"    


    Signature = GetSignature("erni@erni.pl")
    MsgBox (OutMail.SentOnBehalfOfName)

        On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .subject = "This is the Subject line"
        .HTMLBody = strbody & "<br><br>" & Signature
        'You can add files also like this
        '.Attachments.Add ("C:\test.txt")
        .Display
    End With


    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Regards, erni

Community
  • 1
  • 1
erni
  • 83
  • 1
  • 4
  • 12
  • Try : `oMyItem.SentOnBehalfOfName = "myself@here"` – Larry Jan 25 '13 at 08:16
  • you can refer to http://stackoverflow.com/questions/10528075/outlook-auto-forward-set-replyto-email-to-orginal-sender-rather-than-forwarder 's answer – Larry Jan 25 '13 at 08:22
  • Ok but this is setting the value of the from field. I need to get the value from field. – erni Jan 25 '13 at 09:23
  • You want to get the "from" field from a mailitem you just created? – Larry Jan 25 '13 at 09:27
  • e.g. when I click reply I want to get from field(I have 3 different mail addresses and three different signatures) when I reply from first address I want e.g first signature. So i need to get the from field value. – erni Jan 25 '13 at 09:35
  • I personally do not have multiple account set up in my outlook. But maybe you can try `SenderUsingAccount` `SenderEmailAddress` `SenderName` properties – Larry Jan 25 '13 at 09:47

2 Answers2

1

SenderName is the field name for 'From' field.

Shog9
  • 156,901
  • 35
  • 231
  • 235
ksp585
  • 1,720
  • 15
  • 29
0

From is SentOnBehalfOfName. In normal use, it is empty until the item has been sent.

Do not choose the From manually.

Sub replySentOnBehalf()

Dim objMsg As mailitem

Set objMsg = ActiveInspector.currentItem.reply
objMsg.SentOnBehalfOfName = "someone@somewhere.com"

' Now that objMsg.SentOnBehalfOfName is available run your code

objMsg.Display

Set objMsg = Nothing

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52