Prompt email subject line when creating a new email

K

kaiser

I am looking to
write somethig for Outlook so that whenever I open a blank email to
send a new email it pops up with a window asking me to select one of
four choices for the subject....is this possible?
If so, can someone give me some guidance on how to do this? thanks! I
am really struggling with it....if anyone can slap a rough version of
it together in 5 minutes or has a procedure that already does this I
would really appreciate seeing it as I really dont know where to start.
 
M

Michael Bauer

Am 25 Oct 2005 22:51:20 -0700 schrieb kaiser:

It will take you a little more than 5 minutes but it´s easy. Add an UserForm
to your VBA project. If you´re sure you´ll stick with a specified and little
number of choices I´d use e.g. 4 Option (or Radio) Buttons on it. If the
number of choices can increase then I´d use a ComboBox.

Call UserForm.Show 1 from within the NewInspector event and if the user
clicks the OK button on your UserForm then read which choice is selected.
 
K

kaiser

Thanks Michael - appreciate your answer....can you help me with the
code for the NewInspector? I am lost without the Macro Recorder
unfortunately.
 
M

Michael Bauer

Am 25 Oct 2005 23:34:32 -0700 schrieb kaiser:

Private WithEvents m_colInspectors As Outlook.Inspectors

Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
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
' call now your form
Endif
Endif
End Sub
 
K

kaiser

THanks M...when i copy and paste this into my VBA editor (in a module)
i am presented with the error

"Only Valid in an Object Module"
 
M

Michael Bauer

Am 26 Oct 2005 00:23:00 -0700 schrieb kaiser:

That´s correct, events can be received in object module only. You can use
the ThisOutlookSession module e.g.
 
K

kaiser

I am sorry to be a pain but I cant seem to get it working. I have
dropped the text into the
"ThisOutLookSession" under Microsoft Office Outlook Objects and it now
doesnt come up with an error. I have also created a userform UserForm1
and tried to call it within the procedure from under the
ThisOUtlookSession window...but nothing is happening

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.Show
End If
End If
End Sub
 
M

Michael Bauer

Am 26 Oct 2005 01:19:41 -0700 schrieb kaiser:

After copying my sample into ThisOutlookSession please save the project,
place the cursor into the Application_Startup event and press F5. While
developing the code you´ll need to re-start Application_Startup after every
code changes (either manually as explained or by closing and re-opening
Outlook itself).

The NewInspector event then should be executed if you´re opening an item.
 
K

kaiser

It seems to run once only though...so if I place the code as you
suggest and then run the application (as you sugges) and open an email
it prompts me for my choice, however, if I choose an option and then
open another email it doesnt prompt me for a input unless I rerun the
program with F5 in the Startup
 
K

kaiser

It seems to run once only though...so if I place the code as you
suggest and then run the application (as you sugges) and open an email
it prompts me for my choice, however, if I choose an option and then
open another email it doesnt prompt me for a input unless I rerun the
program with F5 in the Startup
 
K

kaiser

Below in ThisOUtlookSession

Private WithEvents m_colInspectors As Outlook.Inspectors

Private Sub Application_Startup()
Set m_colInspectors = Application.Inspectors
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.Show
End If
End If
End Sub



And this as the form (which doesnt work either : perhaps you can help
me too?)
Private Sub CommandButton1_Click()
With UserForm1

Dim oItem As Outlook.MailItem

If .OptionButton1.Value = True Then oItem.Subject = "Test"



UserForm1.Hide
End With

End Sub


Private Sub Frame1_Click()

End Sub

Private Sub OptionButton1_Click()

End Sub

Private Sub OptionButton2_Click()

End Sub

Private Sub OptionButton3_Click()

End Sub

Private Sub UserForm_Click()

End Sub
 
M

Michael Bauer

Am 26 Oct 2005 22:11:39 -0700 schrieb kaiser:

Please try this:

<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
</ThisOutlookSession>

<UserForm1>
Option Explicit
Public SelectedSubject As String

Private Sub CommandButton1_Click()
If OptionButton1.Value = True Then
SelectedSubject = "Test"
End If
Hide
End Sub
</UserForm1>
 
K

kaiser

Fantastic! It works perfectly! Thank you very very much for all your
help.

If I want to send this to someone who is very computer illiterate so
that they can use it...is there anyway that I can write this into a
single file that they double click to execute and run? Also, If the
computer illiterate doesnt want to use it anymore, is there a way that
can I send a single file that would remove this ?
 
M

Michael Bauer

Am 26 Oct 2005 23:52:20 -0700 schrieb kaiser:

You could copy your project file (*.otm) from:
C:\Dokumente und Einstellungen\[User]\Anwendungsdaten\Microsoft\Outlook

to the other users computer. But note: Because OL can manage one project
only, the other user would loose all existing functions (if there´s any code
in his *.otm file already).

At least OL VBA isn´t for distributing. The recommended way is using COM
Add-Ins, which you can´t unfortunately develop with VBA.
 
K

kaiser

Hi
Can you give me one last bit of help with this please? i am trying to
send this to 5 other people (by copying the file to the users
directory). I can get it to run perfectly on their maching but have to
poen VBA on their pc and run the Application_Startup event (by
pressing F5)....closing and reopening outlook doesnt seem to work...is
there any way that i can get this to start by having them do something
more simple than open vba and starting it manually? Opening and
closing outlook would be perfect...but as I said, it doesnt seem to
work?
 

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