mostafa_e90
12-23-2015, 01:40 PM
Hi all,
Im trying to write a vba code with a userform combobox. Basically, I want an inputbox to popup with a predefined droplist. And depending on which option the user chooses from the list, I want to send an email to a specific recipient. However, when I run my code now, the combobox appears with the dropdown list, but when I choose an option from the list nothing happens. I would really appreciate if someone can point out what's wrong with my code. Thx in advance!
Public Sub CommandButton1_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Public Sub UserForm_Initialize()
With ComboBox1
.AddItem "Option 1"
.AddItem "Option 2"
.AddItem "Option 3"
End With
End Sub
Public Sub mostafa_code()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Select Case lstNum
Case 0
With objMsg
.To = "user1 email address"
.Subject = "This is the subject 1"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
End Select
Case 1
With objMsg
.To = "user2 email address"
.Subject = "This is the subject 2"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
Case 2
With objMsg
.To = "user3 email address"
.Subject = "This is the subject 3"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
End Select
End Sub
Im trying to write a vba code with a userform combobox. Basically, I want an inputbox to popup with a predefined droplist. And depending on which option the user chooses from the list, I want to send an email to a specific recipient. However, when I run my code now, the combobox appears with the dropdown list, but when I choose an option from the list nothing happens. I would really appreciate if someone can point out what's wrong with my code. Thx in advance!
Public Sub CommandButton1_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Public Sub UserForm_Initialize()
With ComboBox1
.AddItem "Option 1"
.AddItem "Option 2"
.AddItem "Option 3"
End With
End Sub
Public Sub mostafa_code()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
Select Case lstNum
Case 0
With objMsg
.To = "user1 email address"
.Subject = "This is the subject 1"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
End Select
Case 1
With objMsg
.To = "user2 email address"
.Subject = "This is the subject 2"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
Case 2
With objMsg
.To = "user3 email address"
.Subject = "This is the subject 3"
.Categories = "Test"
.BodyFormat = olFormatPlain ' send plain text message
.Display
End With
Set objMsg = Nothing
End Select
End Sub