PDA

View Full Version : Solved: wordmail: issues with displaying inputboxes & newly created mail items



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

Carmi
05-09-2006, 06:44 PM
Can anyone help? I just need to find a work around for maximising the wordmail window once the input boxes have been completed.

Regards,

Carmi


I have posted a similar thread on http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba&tid=9ea3d70b-ffd9-4f00-88b0-c1c8c0c7f19e&lang=en&cr=US&p=1

Killian
05-16-2006, 01:14 PM
objMailItem.Display would bring it back to the top

Carmi
05-18-2006, 02:45 AM
Dear Killian - I cant believe that it was as easy as that!!!

Thank you so much you are a legend :bow:

I have many more questions regarding my code and making it more efficient but for all intensive purposes I now have something that works. I assume that it would be best to raise new post specific to any further issues I have rather than post here so have marked this as solved

Again thanks for taking the time to read my post and reply it is greatly appreciated.

I have re-posted the final code in case it helps anyone else (some changes)



'Thanks to the following for providing most of the source code
'Sue Mosher &
'Eric Legualt - http://blogs.officezealot.com/legault/articles/2224.aspx
'Samuel Wright - www.vbaexpress.com/forum/showthread.php?t=6366&highlight=word+editor+outlook
'Killian http://www.vbaexpress.com/forum/showthread.php?p=64451#post64451(post includes further background)

'Note: In order for this code to work the person names smart tags must be enabled (Options/Other)

Sub objMailItem_Open(Cancel As Boolean)

Dim objRecipient As Recipient
Dim objSubject As String

On Error Resume Next

'Select only mails where To and Subject are blank - this should only be New Mails
If objMailItem.To = "" And objMailItem.subject = "" Then
GoTo newMail
Else: Exit Sub
End If

newMail:
With objMailItem

'Minimises the WordMail window so the input box can be seen if Word is the mail editor
'NOTE: If On Error Resume Next is not referenced this does not work.
'Provided by Samuel Wright
If ActiveInspector.IsWordMail = True Then
Application.ActiveInspector.WindowState = olMinimized
End If

'Input messagebox for Client Name or Project Number
strEmail = InputBox("Please Input Appropriate Job Number or Client Name", "Job Number")

'If user does not want to send mail to project mailbox
If strEmail = "" Then
GoTo killSub
'Set mailbox Address and email Subject line
Else: objMailItem.CC = strEmail
'Resolve the address to find the correct Project email address eg 9999@sipgroup.com
objMailItem.Recipients.ResolveAll
End If

'Input box for Subject Line
objSubject = InputBox("Please Include a Descriptive Subject", "Subject")

objMailItem.subject = strEmail + " " + "-" + " " + objSubject

'Display email if Word is mail editor
'Provided by Killian
If ActiveInspector.IsWordMail = True Then
objMailItem.Display
End If

If objSubject = "" Then
GoTo killSub
End If
End With

killSub:
If ActiveInspector.IsWordMail = True Then
objMailItem.Display
End If

End Sub

Killian
05-18-2006, 12:19 PM
I'll be honest... it took me 20 minutes of flicking windows around with API calls before I realised! :rofl:

Excellent post btw. Like your style :thumb