tlcsupport
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
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
ASKER
Thanks really handy.. I'll take a look.
Thanks...
not closed yet!
Thanks...
not closed yet!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.SentOnBehalfOfNam e = "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.Active Explorer
'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.I tem(1)
'Create a Reply template
Set oNewMail = oSelectedMail.ReplyAll
Set oNewMail.SentOnBehalfOfNam e = "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
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.SentOnBehalfOfNam
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.Active
'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.I
'Create a Reply template
Set oNewMail = oSelectedMail.ReplyAll
Set oNewMail.SentOnBehalfOfNam
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
ASKER
Hmmm... If I delete the
Set oNewMail.SentOnBehalfOfNam e = "user@address.com" line and add
.SentOnBehalfOfName = "user@address.com" with the With statement it works...
Set oNewMail.SentOnBehalfOfNam
.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.
Regards,
Rob.
http://answers.google.com/answers/threadview?id=431385
Regards,
Rob.