kballan2023
New Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Exchange Server
I am trying to incorporate a selection from a userform combobox into the body of an email that is being forwarded. I am trying to write the selection to a defined variable strDispute and then concatenate it into standard text in the htmlbody. Everything works ok but for the fact that no matter which item I select from the combobox, the only item that gets concatenated into the body of my forwarded email is Choice 1
I believe I have a fairly standard configuration for my UserForm, the code of which is provided below
Option Explicit
Private Sub CommandButton1_Click()
Dim lstNo As Integer
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub UserForm_Activate()
With ComboBox1
.AddItem "Choice 1"
.AddItem "Choice 2"
.AddItem "Choice 3"
End With
End Sub
My macro code is provided below
Sub ForwardEmail()
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim strDispute As String
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.CurrentItem.Forward
UserForm1.Show
Select Case lstNo
Case -1
' -1 is what you want to use if nothing is selected
strDispute = ""
Case 0
strDispute = "Choice 1"
Case 1
strDispute = "Choice 2"
Case 2
strDispute = "Choice 3"
End Select
myItem.Display
With myItem
.Recipients.Add "email@mail.com"
.Subject = "Subject"
.HTMLBody = "<HTML><BODY>Hi Fred,<br><br> Please see below disputed MVF lead. Issue was " & strDispute & ". </BODY></HTML>" & myItem.HTMLBody
End With
Set myItem = Nothing
End Sub
I am very new to VBA coding so have probably broken countless rules, but hoping someone might be able to advise what I need to do to achieve the intended functionality.
I believe I have a fairly standard configuration for my UserForm, the code of which is provided below
Option Explicit
Private Sub CommandButton1_Click()
Dim lstNo As Integer
lstNo = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub UserForm_Activate()
With ComboBox1
.AddItem "Choice 1"
.AddItem "Choice 2"
.AddItem "Choice 3"
End With
End Sub
My macro code is provided below
Sub ForwardEmail()
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim strDispute As String
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.CurrentItem.Forward
UserForm1.Show
Select Case lstNo
Case -1
' -1 is what you want to use if nothing is selected
strDispute = ""
Case 0
strDispute = "Choice 1"
Case 1
strDispute = "Choice 2"
Case 2
strDispute = "Choice 3"
End Select
myItem.Display
With myItem
.Recipients.Add "email@mail.com"
.Subject = "Subject"
.HTMLBody = "<HTML><BODY>Hi Fred,<br><br> Please see below disputed MVF lead. Issue was " & strDispute & ". </BODY></HTML>" & myItem.HTMLBody
End With
Set myItem = Nothing
End Sub
I am very new to VBA coding so have probably broken countless rules, but hoping someone might be able to advise what I need to do to achieve the intended functionality.