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.
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.
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
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
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.
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
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
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"
<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>
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 ?
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.
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?