여러 개의 ListBox 값을 하나의 변수에 할당하고 전자 메일에 "to"필드에 넣는 방법

StackOverflow https://stackoverflow.com//questions/25060470

문제

두 개의 목록 상자에서 여러 값을 선택하고 두 개의 개별 변수에 할당 할 수 있습니다.그런 다음 선택 사항이 포함 된 변수를 사용하고 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
.

도움이 되었습니까?

해결책

목록 상자에 유효한 이메일 주소가 포함되어있는 ASYING, 나는

를 제안합니다

  • ListBox1.MultiSelect = fmMultiSelectMulti
  • 를 정의하십시오
  • Ctrl 키를 사용하여 여러 메일 주소를 선택합니다
  • 선택한 모든 주소를 ListBox에서 하나의 단일 문자열로 연결합니다.

_

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
.

  • 2nd ListBox의 반복 ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top