Outlook Macro to Modify Subject and Send Message

  • Thread starter Thread starter jaysonsch
  • Start date Start date
J

jaysonsch

Good afternoon,

I'd like to create a Macro for Outlook 2003 to modify the subject of a
message to prepend a given phase and send the message. I can't imagine
that this would be too hard of a task, unfortunately, I'm not sure
where to begin.

Can someone help me out here? If you have the solution, that's great.
But I'd really like some links to training docs also to familiarize
myself with Macros in Outlook.

Thanks!
 
Through a bit of research, I found the code to create a button that
will append a phrase to a subject and then send the message using the
Send function of the olMailItem attribute. However, address resolution
seems to be a bit messy. Upon investigation, it seems that it would be
a lot nicer if I could just send the message by somehow invoking the
functionality of the Outlook Send button. Is this a possibility? If
not, is there some commonly used error handling code for this? Please
help!
 
Am 25 Sep 2006 20:22:34 -0700 schrieb jaysonsch:

Before callign the Send method you can call the MailItem´s
Recipients.ResolveAll function.
 
Micheal,

Thanks for your help. What I put togehter can be found at the bottom
of this post. The one problem that I'm running into right now,
however, is that if I do the following...

- Compose a Message
- Enter a valid address in one of the address fields
- Resolve the address using Outlook's check name feature
- Remove the address and leave the address field blank
- Continue to compose the message
- Activate the Macro again

....my script then thinks that there is still a recipient even though
none appears in the TO, CC, or BCC fields. To validate this, I have
created a message box that shows these values. Am I checking the wrong
property to see if there is an addressee or is this a problem with
Outlook? I'm developing this on Outlook 2003 SP2.

Thanks!

------------------------------------------------------------------
CODE:



Public Sub Popup()
With Application.ActiveInspector
If TypeOf .CurrentItem Is Outlook.MailItem Then
'Validate that at least one recipient is
specified
If (.CurrentItem.To = "") And (.CurrentItem.CC
= "") And (.CurrentItem.BCC = "") Then
MsgBox "There must be at least one name
or distribution list in the TO, CC, or BCC box.", 48, "Error"
Else
'Resolve All Addresses
If Not
..CurrentItem.Recipients.ResolveAll Then
Set myRecipients =
..CurrentItem.Recipients

'Count Number of Recipients
Dim intCount As Integer
intCount = myRecipients.Count

'Determine Recipients that did not
resolve and echo in MsgBox
Dim strErrtxt As String
strErrtxt = "The addresses of the
following recipients could not be resolved:" & vbCrLf
For Each myRecipient In
myRecipients
If Not myRecipient.Resolved
Then
strErrtxt = strErrtxt &
vbCrLf & myRecipient.Name
End If
Next
strErrtxt = strErrtxt & vbCrLf &
vbCrLf & "Please use the ""Check Name"" feature from the Tools Menu to
validate the addresses specified."
MsgBox strErrtxt, vbExclamation,
"Error"
Else
'DEBUG: Echo that Resolve was OK
MsgBox "Resolve OK"

'
'The next few lines are commented
out to faciliate testing of the resolve functionallity
'
'.CurrentItem.Subject = "PREFIX: "
& .CurrentItem.Subject
'.CurrentItem.Send
End If
End If
'DEBUG: Display Fields
MsgBox "To: " & .CurrentItem.To & vbCrLf &
"CC: " & .CurrentItem.CC & vbCrLf & "BCC: " & .CurrentItem.BCC

End If
End With
End Sub
 
Am 26 Sep 2006 07:15:45 -0700 schrieb jaysonsch:

I don´t understand what the problem is and you do not "Remove the address
and leave the address field blank" as far as I can see.
 
Back
Top