C
Carmi
Outlook 2003 (SP2)
Windows XP (SP2)
(I have also posted this issue at
http://www.vbaexpress.com/forum/showthread.php?t=7989 but have had no reply)
Dear All – I am relatively new to this forum (and VBA in general) but hope
that someone can help as I really want to complete this code so I can roll it
out to a few members of my team who really NEED it (I know should use COM
ADDIN but don’t know how to convert this to VB to create Addin)
I have managed to piece together some code from different forums’ which
accomplishes the following;
• User opens new instance of a mail
• When the To: & Subject: fields are empty 2 input boxes are displayed. The
first asks the user to input a job number or client name the second asks the
user to input a subject line.
• New mail shown with the Job No/Client Name in CC field and a combination
of Job No/Client Name & Subject line shown in Subject field.
This ensures that the email is ‘copied’ to the correct project mailbox and
that the client name or job number are referenced in the subject line of new
mails.
The following code works if the mail editor is Outlook however, I had a
number of problems if the mail editor was word. Firstly if the editor was
word the input boxes would hide behind the instance of wordmail. I found
some code (provided by Samual Wright) which minimised the wordmail window so
the boxes could be completed and is then meant to maximise the wordmail
window again so the user can edit their mail. Unfortunately the wordmail
only maximises if the their were no other instances of a word document
running (eg if I have a document open then the maximise command does not work)
Can someone help me either refine the minimise/maximise compoenent of the
code so it works correctly or alternativly suggest a better method of
accomplishing the task when word is the email editor.
Code as follows;
'Thanks to Sue Mosher & Eric Legualt
‘http://blogs.officezealot.com/legault/articles/2224.aspx for providing most
of the ‘source code
Sub objMailItem_Open(Cancel As Boolean)
Dim objWordMail As Word.MailMessage
Dim strEmail As String
Dim objRecipient As Recipient
Dim objSubject As String
Dim objMailBody As String
On Error Resume Next
With objMailItem
'Code provided by Samuel Wright 'http://www.vbaexpress.com/forum _
'/showthread.php?t=6366&highlight=word+editor+outlook (is there a better way
to do this?)
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMinimized
End If
'Select only mails where To and Subject are blank - this should
only be New ‘Mails
If .To = "" And .subject = "" Then
'Input messagebox for Client Name or Project Number
strEmail = InputBox("Please Input Appropriate Job Number or
Client Name", _ "Job Number")
End If
'If user does not want to send mail to project mailbox
If strEmail = "" Then
Goto killSub
End If
objMailItem.CC = strEmail
objSubject = InputBox("Please Include a Descriptive Subject",
"Subject")
'Resolve the address to find the correct Project email address eg
'(e-mail address removed)
objMailItem.Recipients.ResolveAll
objMailItem.subject = strEmail + " " + "-" + " " + objSubject
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
‘This dosnt work if another word document running
End If
End With
killSub: With objMailItem
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
‘This dosnt work if another word document running
End If
End With
End Sub
Note: other treads similar to the above I have found on another forum
include. http://www.vbaexpress.com/forum/showthread.php?t=6366
http://vbaexpress.com/forum/showthread.php?t=5042
http://www.vbaexpress.com/forum/showthread.php?t=6283
http://vbaexpress.com/forum/showthread.php?t=3516
Windows XP (SP2)
(I have also posted this issue at
http://www.vbaexpress.com/forum/showthread.php?t=7989 but have had no reply)
Dear All – I am relatively new to this forum (and VBA in general) but hope
that someone can help as I really want to complete this code so I can roll it
out to a few members of my team who really NEED it (I know should use COM
ADDIN but don’t know how to convert this to VB to create Addin)
I have managed to piece together some code from different forums’ which
accomplishes the following;
• User opens new instance of a mail
• When the To: & Subject: fields are empty 2 input boxes are displayed. The
first asks the user to input a job number or client name the second asks the
user to input a subject line.
• New mail shown with the Job No/Client Name in CC field and a combination
of Job No/Client Name & Subject line shown in Subject field.
This ensures that the email is ‘copied’ to the correct project mailbox and
that the client name or job number are referenced in the subject line of new
mails.
The following code works if the mail editor is Outlook however, I had a
number of problems if the mail editor was word. Firstly if the editor was
word the input boxes would hide behind the instance of wordmail. I found
some code (provided by Samual Wright) which minimised the wordmail window so
the boxes could be completed and is then meant to maximise the wordmail
window again so the user can edit their mail. Unfortunately the wordmail
only maximises if the their were no other instances of a word document
running (eg if I have a document open then the maximise command does not work)
Can someone help me either refine the minimise/maximise compoenent of the
code so it works correctly or alternativly suggest a better method of
accomplishing the task when word is the email editor.
Code as follows;
'Thanks to Sue Mosher & Eric Legualt
‘http://blogs.officezealot.com/legault/articles/2224.aspx for providing most
of the ‘source code
Sub objMailItem_Open(Cancel As Boolean)
Dim objWordMail As Word.MailMessage
Dim strEmail As String
Dim objRecipient As Recipient
Dim objSubject As String
Dim objMailBody As String
On Error Resume Next
With objMailItem
'Code provided by Samuel Wright 'http://www.vbaexpress.com/forum _
'/showthread.php?t=6366&highlight=word+editor+outlook (is there a better way
to do this?)
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMinimized
End If
'Select only mails where To and Subject are blank - this should
only be New ‘Mails
If .To = "" And .subject = "" Then
'Input messagebox for Client Name or Project Number
strEmail = InputBox("Please Input Appropriate Job Number or
Client Name", _ "Job Number")
End If
'If user does not want to send mail to project mailbox
If strEmail = "" Then
Goto killSub
End If
objMailItem.CC = strEmail
objSubject = InputBox("Please Include a Descriptive Subject",
"Subject")
'Resolve the address to find the correct Project email address eg
'(e-mail address removed)
objMailItem.Recipients.ResolveAll
objMailItem.subject = strEmail + " " + "-" + " " + objSubject
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
‘This dosnt work if another word document running
End If
End With
killSub: With objMailItem
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
‘This dosnt work if another word document running
End If
End With
End Sub
Note: other treads similar to the above I have found on another forum
include. http://www.vbaexpress.com/forum/showthread.php?t=6366
http://vbaexpress.com/forum/showthread.php?t=5042
http://www.vbaexpress.com/forum/showthread.php?t=6283
http://vbaexpress.com/forum/showthread.php?t=3516