如何将用户表单中的组合框选择传递给调用过程?

时间:2017-01-03 06:18:09

标签: vba outlook-vba

我有一个"发行"不会有太大变化,会有多种选择。填充到我的.TO的唯一值是strP0list中的值,无论我从组合框中选择什么。

Sub OutageNotification()
'-----------------------------------------
'DECLARE AND SET VARIABLES
    Dim myOutlok As Object
    Dim myMailItm As Object
    Dim Signature As String
    Dim strUsrPmt1 As String
    Dim strDistroList As String
    Set otlApp = CreateObject("Outlook.Application")
    Set OtlNewMail = otlApp.CreateItem(olMailItem)
    Dim message, title, defaultValue As String
    message = "Enter your issue"
    title = "Subject InputBox"
    defaultValue = "No Issue"
    strUsrPmt1 = InputBox(message, title, defaultValue, 25, 45)

    strP0list = "List1-1@somewhere.com;List1-2@somewhere.com"
    strP1list = "List2-1@somewhere.com;List2-2@somewhere.com"
    strP2list = "List3-1@somewhere.com;List3-2@somewhere.com"
    strP3list = "List4-1@somewhere.com;List4-2@somewhere.com"
    '-----------------------------------------
    'Get Distribution List
UserForm1.Show

    Select Case lstNum
        Case -1
    '  -1 is what you want to use if nothing is selected
         strDistroList = "Please enter a valid email"
        Case 0
             strDistroList = strP0list
        Case 1
            strDistroList = strP1list
        Case 2
             strDistroList = strP2list
        Case 3
             strDistroList = strP3list
        End Select
'-----------------------------------------
'GET DEFAULT EMAIL SIGNATURE
    'Signature = Environ("appdata") & "\Microsoft\Signatures\"
   ' If Dir(Signature, vbDirectory) <> vbNullString Then
   ' Signature = Signature & Dir$(Signature & "*.htm")
   ' Else:
  '      Signature = ""
   ' End If
   ' Signature = CreateObject("Scripting.FileSystemObject").GetFile    (Signature).OpenAsTextStream(1, -2).ReadAll
'-----------------------------------------
    'CREATE EMAIL
        OtlNewMail.HTMLBody = Signature
    With OtlNewMail
    .To = strDistroList
    .CC = "someone@somewhere.com"
    .Subject = "Notification: " & strUsrPmt1
    .HTMLBody = "<p><font face=""Calibri"" size=""3"">" & "<B>" & "Team-" & "<BR>" & "<BR>" & "</B>" & "<I>" & "This is an important notice about ……(Describe the impacted technology)" _
& "<BR>" & "<BR>" & "</I>" & "<B>" & "What's happening?" & "</B>" & "<BR>" & "<BR>" & "<I>" & _
"In order to continue to reduce our …… (Describe the issue or effort)" & "</I>" & "<BR>" & "<BR>" & "<B>" & "What's the impact?" & "</B>" & "<BR>" & "<BR>" _
& "<I>" & "Beginning at 8 PM EST on Friday, December 9, network and phone connectivity will be .... (Describe the impact)" & _
"</I>" & "<BR>" & "<BR>" & "<B>" & "What's not impacted?" & "</B>" & "<BR>" & "<BR>" & "<I>" & "This does not impact remote.... (Describe what is not impacted)" _
& "</I>" & "<BR>" & "<BR>" & "<B>" & "Questions?" & "</B>" & "<BR>" & "<BR>" & "<I>" & "Contact me directly for questions or concerns." & "</I>" & "<BR>" & "<BR>" & Signature
.Display
'.Send
End With

'-----------------------------------------
'CLEANUP
    Set OtlNewMail = Nothing
    Set otlApp = Nothing
    Set otlAttach = Nothing
    Set otlMess = Nothing
    Set otlNSpace = Nothing
'-----------------------------------------

End Sub

Private Sub UserForm_Initialize()
  With ComboBox1
    .AddItem "BPS Distribution"
    .AddItem "MSH Distribution"
    .AddItem "Pharma Distribution"
    .AddItem "HR Contact Center Distribution"
  End With
End Sub

Private Sub btnOK_Click()
    lstNum = ComboBox1.ListIndex
    Unload Me
End Sub

有人可以提供一些帮助吗?

1 个答案:

答案 0 :(得分:0)

从用户表单传递数据。

Option Explicit ' Not mandatory but you should consider it to be mandatory

Public lstNum As Long

Sub OutageNotification()