Using input boxes when word is your email editor

G

Guest

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
 
M

Michael Bauer

Am Tue, 9 May 2006 18:10:02 -0700 schrieb Carmi:

That´s a good idea with the WindowState property.

The next step should be simple: If you minimize a window and the application
has other windows visible then the focus changes to the next visible window.
Due to that the ActiveInspector changes.

So simply declare a variable and store the reference on the Inspector you
want to work with. Additionally I´d store the WindowState itself.

A very short sample:

Dim Inspector as Outlook.Inspector
Dim WindowState As Long

Set Inspector=Application.ActiveInspector
WindowState=Inspector.WindowState
Inspector.WindowState=olMinimized
'...
Inspector.WindowState=WindowState
 
G

Guest

Hi Michael - thanks for the reply. I had the windowstate property in the
code already which worked when minimising but not when maximising (if a word
doc was already active). However, I have now used the .display method to
maximise the mail.

The following link is to the working (but not perfect) code.
http://www.vbaexpress.com/forum/showthread.php?t=7989
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top