Domanda

I am using VBA code to forward emails to my CRM software.

My Outlook is in Portuguese, so the forwarded email comes with the fields:

De: sender@sender.com

Para: recipient@recipient.com

I want to translate this field labels to English for emails sent by this macro in specific. That would return:

From: sender@sender.com

To: recipient@recipient.com

Maybe change those fields in the Item body.

Here is my VBA code to forward the email:

Sub ForwardEmailOnButtonClick()
     Dim oApp As Outlook.Application
     Dim objFolder As Outlook.MAPIFolder
     Set oApp = New Outlook.Application
     Set objNS = Application.GetNamespace("MAPI")
     Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
     Set objFolder = objInbox.Folders("Helpdesk")
     Dim oEmail As Outlook.MailItem

     For Each objItem In Application.ActiveExplorer.Selection
         If objFolder.DefaultItemType = olMailItem Then
             If objItem.Class = olMail Then

                 Set myForward = objItem.Forward

                 Set objRecip = myForward.Recipients.Add("recipient@rec.com") 

                 myForward.SenderEmailAddress = objItem.SenderEmailAddress
                 myForward.SenderName = objItem.SenderName                  

                 myForward.Send

             End If
         End If
     Next
End Sub

EDIT:

Since some posts and David's comment warned me that changing the language is something harder to do, I would like to focus on changing those two labels to "From:" and "To:" so that my CRM software can recognise them.

The approach does not need go through the difficulties of changing the language.

È stato utile?

Soluzione

OK try this, which should change the fields in the item's .Body:

         myForward.SenderEmailAddress = objItem.SenderEmailAddress
         myForward.SenderName = objItem.SenderName

        'Attempt a simple text replace from Portugese to English
        ' this should replace the FIRST instance of "De:" and "Para:" and "FWD:" with the English equivalent

        myForward.Body = Replace(myForward.Body, "De: ", "From: ", 1, 1)
        myForward.Body = Replace(myForward.Body, "Para: ", "To: ", 1, 1)

        'Optionally, replace "FW" with Portugese equivalent:
        'myForward.Subject = Replace(myForward.Subject, "FW: ", "_REPLACEMENT TEXT_", 1, 1)
        myForward.Send
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top