我试图能够在两个列表框中选择多个值并分配给两个单独的变量。然后,我想获取包含选择的变量,并生成一个电子邮件,其中包含填充Outlook电子邮件中“TO”字段的变量内容。现在我得到一个运行时错误94 - 无效使用Null。
感谢您的帮助!
Dim EAddress, MAddress As String
Public Sub UserForm_Initialize()
Emailfrm.EmpEmaillb.RowSource = "Searched_Employee_Email"
Emailfrm.ManagerEmaillb.RowSource = "Searched_Manager_Email"
End Sub
Public Sub Email_Click()
Dim OLobjMsg, NewMsg As Object
EAddress = Emailfrm.EmpEmaillb.Value
MAddress = Emailfrm.ManagerEmaillb.Value
Set objMsg = CreateObject("Outlook.Application")
objMsg.Session.Logon
Set NewMsg = objMsg.CreateItem(0)
With NewMsg
.To = EAddress & MAddress
.Subject = "BT Employee Database Inquiry Email"
'.Body = "Have a great weekend!"
End With
Unload Me
NewMsg.Display
End Sub
答案 0 :(得分:0)
假设您的列表框包含有效的电子邮件地址,我建议
ListBox1.MultiSelect = fmMultiSelectMulti
_
Private Sub CommandButton1_Click()
Dim LBCnt As Integer, AllAddr As String
AllAddr = ""
For LBCnt = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(LBCnt) Then
If AllAddr = "" Then
AllAddr = ListBox1.List(LBCnt)
Else
AllAddr = AllAddr & ";" & ListBox1.List(LBCnt)
End If
End If
Next LBCnt
Debug.Print AllAddr
End Sub