pk247
11-24-2015, 12:14 PM
Hi Everyone,
I hope you are all well. I'm hoping maybe someone could possibly help me with a piece of code. I got the idea that this might be possible from Graham Mayor in this post (http://www.vbaexpress.com/forum/showthread.php?54200-Outlook-VBA-help-please-Automate-and-Bcc-based-on-word-in-subject-line) I created a few weeks back. What I see is that we can reference an excel list and use it for other code to reference.
What I'd like to do then (and I've failed miserably thus far on my own with google) is have a list from an Excel Sheet display in a Combo Box rather than having to edit the ComboBox1.AddItem "..." each time. Assuming this is possible I would then like to be able to use the selection from within the Combobox to tack on to my subject line.
The code I have thus far is very manual to update each time I work on a new Project. I really hope what I've written makes sense and is possible. I'd appreciate any help or pointers in the right direction if anyone could spare some time please.
Thanks! and if I need to clarify anything please get in touch.
Cheers,
Paul, Ireland :beerchug:
WITHIN THE USERFORM1
Private Sub ComboBox1_Change()
End Sub
Private Sub Userform_Initialize()
ComboBox1.AddItem "no change"
ComboBox1.AddItem "ABCDEF123111"
ComboBox1.AddItem "ABCDEF123555"
ComboBox1.AddItem "ABCDEF123777"
ComboBox1.AddItem "ABCDEF123888"
ComboBox1.AddItem "ABCDEF123999"
End Sub
Private Sub CommandButton1_Click()
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
WITHIN THE CODE TO SELECT THE PROJECT CODE
Public lstNo As Long
Public Sub SubjectUpdate()
Dim objItem As Object
Dim oMail As Outlook.MailItem
Set objItem = GetCurrentItem()
Set oMail = Application.ActiveInspector.CurrentItem
With oMail
UserForm1.Show
Select Case lstNo
Case 0
oMail.Subject = objItem.Subject
Case 1
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123111"
Case 2
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123555"
Case 3
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123777"
Case 4
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123888"
Case 5
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123999"
End Select
End With
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function
I hope you are all well. I'm hoping maybe someone could possibly help me with a piece of code. I got the idea that this might be possible from Graham Mayor in this post (http://www.vbaexpress.com/forum/showthread.php?54200-Outlook-VBA-help-please-Automate-and-Bcc-based-on-word-in-subject-line) I created a few weeks back. What I see is that we can reference an excel list and use it for other code to reference.
What I'd like to do then (and I've failed miserably thus far on my own with google) is have a list from an Excel Sheet display in a Combo Box rather than having to edit the ComboBox1.AddItem "..." each time. Assuming this is possible I would then like to be able to use the selection from within the Combobox to tack on to my subject line.
The code I have thus far is very manual to update each time I work on a new Project. I really hope what I've written makes sense and is possible. I'd appreciate any help or pointers in the right direction if anyone could spare some time please.
Thanks! and if I need to clarify anything please get in touch.
Cheers,
Paul, Ireland :beerchug:
WITHIN THE USERFORM1
Private Sub ComboBox1_Change()
End Sub
Private Sub Userform_Initialize()
ComboBox1.AddItem "no change"
ComboBox1.AddItem "ABCDEF123111"
ComboBox1.AddItem "ABCDEF123555"
ComboBox1.AddItem "ABCDEF123777"
ComboBox1.AddItem "ABCDEF123888"
ComboBox1.AddItem "ABCDEF123999"
End Sub
Private Sub CommandButton1_Click()
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
WITHIN THE CODE TO SELECT THE PROJECT CODE
Public lstNo As Long
Public Sub SubjectUpdate()
Dim objItem As Object
Dim oMail As Outlook.MailItem
Set objItem = GetCurrentItem()
Set oMail = Application.ActiveInspector.CurrentItem
With oMail
UserForm1.Show
Select Case lstNo
Case 0
oMail.Subject = objItem.Subject
Case 1
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123111"
Case 2
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123555"
Case 3
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123777"
Case 4
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123888"
Case 5
oMail.Subject = oMail.Subject & " - PROJECT CODE: ABCDEF123999"
End Select
End With
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function