Help with prompting for a subject

K

kaiser

Hi

Can anyone please help me. I am trying to write a macro that does the
following.


When an email is opened (either a new email or a reply / forward) the
macro must check if there is content inthe subject line. If there is,
then it must do nothing but open the email ready for forward or reply,
however, if there is NO subject it must bring up a msgbox saying "No
Subject"


Can anyone help me with this? SOmeone the forum previously helped me
with the following code (which when opening an email, prompted you to
chose from one of five choices from a userform and would enter a
preassigned string inot the subject). Perhaps this code will help


Thnks!


under modules:


Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
End Sub


under ThisOutlookSession:
Option Explicit
Private WithEvents m_colInspectors As Outlook.Inspectors
Private WithEvents CurrentInspector As Outlook.Inspector


Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
End Sub


Private Sub CurrentInspector_Activate()
Dim oMail As Outlook.MailItem
If Len(UserForm1.SelectedSubject) Then
Set oMail = CurrentInspector.CurrentItem
oMail.Subject = UserForm1.SelectedSubject
End If
Set CurrentInspector = Nothing
End Sub


Private Sub m_colInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
If Inspector.CurrentItem.EntryID = vbNullString Then
UserForm1.SelectedSubject = vbNullString
UserForm1.Show
Set CurrentInspector = Inspector
End If
End If
End Sub


and obbiously had the userform
 
M

Michael Bauer

Am 26 Apr 2006 07:09:49 -0700 schrieb kaiser:

You can add the code into the NewInspector procedure. Check
CurrentItem.Subject, if it´s blank then call MsgBox.
 
K

kaiser

Thanks MIchael...but i cant get it to work? Can you assist? One thing
just struck me...obviously when i open an email the subject will be
blank as nothing is inputted yet...meant to say that when the "send"
button is clicked AND the subject line is blank it must bring up a
message box saying that the email subject line is blank...so no email
can go unless there is a subject line.
thanks
 
M

Michael Bauer

Am 27 Apr 2006 03:42:06 -0700 schrieb kaiser:

Ok, in that case please use the ItemSend event instead of the NewInspector
event.
 
K

kaiser

Hello MIchael

THanks - can you help me with the full text please? I am but a
beginner trying to fiddle my way thorugh

thanks!
 
M

Michael Bauer

Am 28 Apr 2006 00:15:02 -0700 schrieb kaiser:

The IDE creates the event procedure automatically for you, simply click into
the Combobox above the code window on the left hand and select
"Application". Then click into the one on the right hand and select
"ItemSend".

Now move the code from the NewInspector event into the new one. Instead of
Inspector.CurrentItem you do have the ref onto the e-mail now directly via
the "Item" variable. So you need to replace NewInspector.CurrentItem by Item
now.

Call UserForm1.Show with a 1 as the argument. That means the Form will be
shown modal, i.e. the code execution stops until the form will be closed
(otherwise the e-mail would be sent out while your form is still shown).

Also copy the code from the Activate event into the ItemSend event after the
line: UserForm1.Show 1. That lines will be executed then after you have
closed the form.
 
K

kaiser

I am sorry to be a pain michael, i cant get this to work. Can you
please drop the actual code onto this chat thread so that i can import
it then execute it line by line to see the effect?
 
M

Michael Bauer

Am 1 May 2006 22:21:53 -0700 schrieb kaiser:

Please show me what you´ve created so far. We can then see if there´s
something wrong.
 
K

kaiser

Okay - thanks

I have this in the modules section

Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
End Sub



and this in the ThisOUtlookSession


Option Explicit
Private WithEvents m_colInspectors As Outlook.Inspectors
Private WithEvents CurrentInspector As Outlook.Inspector





Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
If Item.Now = vbNullString Then
MsgBox ("There is no subject - enter a subject and try again")
'somehow stop the email from going but dont close the email
End If
Set CurrentInspector = Inspector
End If
End If

End Sub

Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
End Sub


Private Sub CurrentInspector_Activate()
Dim oMail As Outlook.MailItem
If Len(UserForm1.SelectedSubject) Then
Set oMail = CurrentInspector.CurrentItem
oMail.Subject = UserForm1.SelectedSubject
End If
Set CurrentInspector = Nothing
End Sub


Private Sub m_colInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector)
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
If Inspector.CurrentItem.EntryID = vbNullString Then
UserForm1.SelectedSubject = vbNullString
UserForm1.Show
Set CurrentInspector = Inspector
End If
End If
End Sub




Thanks
 
M

Michael Bauer

Am 3 May 2006 23:24:20 -0700 schrieb kaiser:

Ok. All you need is this:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
If Trim(Item.Subject) = vbNullString Then
MsgBox ("There is no subject - enter a subject and try again")
'somehow stop the email from going but dont close the email
Cancel=True
End If
End Sub
 
K

kaiser

ah, okay - i see thank you...when the error message comes up it always
comes up behind the email...anyway of making it come up infont of the
email message?
 
M

Michael Bauer

Am 4 May 2006 23:36:21 -0700 schrieb kaiser:

Probably you´re using Word as mail editor. The workaround to show the
message on top would be too much work. My suggest: Think about about using
Outlook as mail editor.
 

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