• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

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
0
tlcsupport
Asked:
tlcsupport
  • 3
  • 3
1 Solution
 
RobSampsonCommented:
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.
0
 
tlcsupportAuthor Commented:
Thanks really handy.. I'll take a look.

Thanks...

not closed yet!
0
 
RobSampsonCommented:
No problem.  I can try to help you with the code if you need....

Rob.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tlcsupportAuthor Commented:
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
0
 
tlcsupportAuthor Commented:
Hmmm... If I delete the

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

.SentOnBehalfOfName = "user@address.com" with the With statement it works...
0
 
RobSampsonCommented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now