Link to home
Start Free TrialLog in
Avatar of tlcsupport
tlcsupportFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Macro to Reply As... From field filled in

Hi,

I've been trying to write a VBA macro in OUtlook that will allow me to create a reply email, preferably with the recipients in there, as Reapl-To-All, but also have the From field filled out...

I know the SentOnBehalfOFName object is required but I cannot work out how to actually do it! This is driving me insane... If there is a better/simpler way to do this can you please share!

Thanks
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, I don't use Outlook, so I can't test any of this, but see if you can customise the code posted here:
http://answers.google.com/answers/threadview?id=431385

Regards,

Rob.
Avatar of tlcsupport

ASKER

Thanks really handy.. I'll take a look.

Thanks...

not closed yet!
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi again...

Run into a brick wall... I've got the macro replying but when I try and set the From field it errors saying 'Invalid Use of Property' for the SentOnBehalfOfName...
The problem is to do with the Set oNewMail.SentOnBehalfOfName = "user@address.com"  but I can't see why this doesn't work...

Below is my script:

Public Sub ReplyToAllEx()

Dim oExplorer As Outlook.Explorer
Dim oSelectedMail As MailItem
Dim oNewMail As MailItem

    On Error GoTo Err
   
    Set oExplorer = Outlook.Application.ActiveExplorer
   
    'Check if something is selected
    If oExplorer.Selection.Count > 0 Then
       
        'Get the first item selected (currently only supports single selection)
        Set oSelectedMail = ActiveExplorer.Selection.Item(1)
           
            'Create a Reply template
            Set oNewMail = oSelectedMail.ReplyAll
          Set oNewMail.SentOnBehalfOfName = "user@address.com"          

            With oNewMail
               
                'Change the body
                .Body = .Body & Chr(13) & Chr(13)
                .Body = .Body & Chr(13) & Chr(13)
                .Body = .Body & "<< --- ORIGINAL MESSAGE --- >>"
                .Body = .Body & Chr(13) & Chr(13)
                .Body = .Body & oSelectedMail.Body
               
                'Display the new mail before sending it
                .Display
           
            End With
           
        'End If
       
    End If
   
    Exit Sub
   
Err:
   
    MsgBox Err.Description, vbCritical
   
End Sub
Hmmm... If I delete the

Set oNewMail.SentOnBehalfOfName = "user@address.com"    line and add

.SentOnBehalfOfName = "user@address.com" with the With statement it works...
Yeah, that would be because the SentOnBehalfOfName is just a property, not an object, so the Set keyword would not be required.  Putting it inside the With block as you have done should be right.

Regards,

Rob.