Blank Subject Warning?

  • Thread starter Thread starter Ben Rodden
  • Start date Start date
B

Ben Rodden

Hello,

I am trying to write a vba macro in Outlook that will
stop a message from being sent if the user has not
entered a subject. Here is the code that I have so far:

Private Sub application_itemsend(ByVal item As Object,
cancel As Boolean)

If item.Subject = "" Then

cancel = True

Dim iMsgBoxSel

iMsgBoxSel = MsgBox("Please fill in the subject
before sending.", vbSystemModal, "Missing Subject")

If iMsgBoxSel = vbOK Then



End If

End If

End Sub

This code works perfectly, except that the main Outlook
window becomes active after the macro is done running. I
want the active window to be the new message.

Any suggestions would be greatly appreciated!

Thanks!
 
Hi-

You could use the SetForegroundWindow() API function.
You'll need the Handle of the new mail message window. You
could get this by using GetForegroundWindow at the
beginning of the application_itemsend() event. There may
be an easier way to get the handle- anyone out there know?

Let me know if you need guidance on using API functions.

-Andrew Cushen
====================================
 
Thanks for the suggestion! I am somewhat familiar with
vb, but I do not have any expierience with API's. Could
you give me some pointers on that.

Do I just need to create the function and call it later
in the macro?

Thanks!
 
Thanks, Sue. I thought there might be an easier way! :-)

-Andrew
=============================
 
I have had a problem with that. When I try to use the
Item identifier it does not recognize it as an object
inside of the function. However, I just realized that I
am using Outlook 2003 on this computer. I tried the code
on another computer with Outlook 2000 and the code that I
have now works perfectly on that computer. Microsoft
must have changed something in the new version regarding
message boxes or something.
 
Back
Top