Carmi
05-03-2006, 09:18 PM
Outlook 2003 (SP2)
Windows XP (SP2)
Dear All – I am new to this forum (and VBA in general) and am encountering a very similar problem with regards to using wordmail as documented in the following thread;
http://www.vbaexpress.com/forum/showthread.php?t=6366
other threads that link to this problem include;
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
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.The above works fine when using outlook mail but if the user has selected word as their mail editor I get the same problem you experienced with regards to your form being displayed behind the word mail window (in my case the 2 input boxes are hidden).
I tried to implement the workaround as quoted below by minimising/maximising the wordmail window which worked… but unfortunately only some of the time.
If ActiveInspector.IsWordMail = True Then _
Application.ActiveInspector.WindowState = olMinimized
SubjectNameForm.Show
Exit Sub
If ActiveInspector.IsWordMail = False Then
SubjectNameForm.Show
End If
If the word application is open and a word document active then after the user completes the input boxes the wordmail is generated and maximised but not brought to the front.
I have copied my code in below for you reference and hope that someone will be able to help or advise a better way of trying to accomplish this. As advised I am a newbie so feel free to suggest any other changes to the code.
Thanks in advance
Carmi
'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
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
'.subject = "P:"
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 9999@sipgroup.com
objMailItem.Recipients.ResolveAll
objMailItem.subject = strEmail + " " + "-" + " " + objSubject
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
End If
End With
killSub: With objMailItem
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
End If
End With
End Sub
Windows XP (SP2)
Dear All – I am new to this forum (and VBA in general) and am encountering a very similar problem with regards to using wordmail as documented in the following thread;
http://www.vbaexpress.com/forum/showthread.php?t=6366
other threads that link to this problem include;
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
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.The above works fine when using outlook mail but if the user has selected word as their mail editor I get the same problem you experienced with regards to your form being displayed behind the word mail window (in my case the 2 input boxes are hidden).
I tried to implement the workaround as quoted below by minimising/maximising the wordmail window which worked… but unfortunately only some of the time.
If ActiveInspector.IsWordMail = True Then _
Application.ActiveInspector.WindowState = olMinimized
SubjectNameForm.Show
Exit Sub
If ActiveInspector.IsWordMail = False Then
SubjectNameForm.Show
End If
If the word application is open and a word document active then after the user completes the input boxes the wordmail is generated and maximised but not brought to the front.
I have copied my code in below for you reference and hope that someone will be able to help or advise a better way of trying to accomplish this. As advised I am a newbie so feel free to suggest any other changes to the code.
Thanks in advance
Carmi
'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
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
'.subject = "P:"
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 9999@sipgroup.com
objMailItem.Recipients.ResolveAll
objMailItem.subject = strEmail + " " + "-" + " " + objSubject
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
End If
End With
killSub: With objMailItem
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMaximized
End If
End With
End Sub