• Create mailing list address array (Excel 2k VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Create mailing list address array (Excel 2k VBA)

    Author
    Topic
    #439043

    I want to create an easily-manageable mailing list on an Excel sheet that can be read into an array variable and passed to a sendmail command: ActiveWorkbook.SendMail Recipients:=Array(address1,address2,etc.). The addresses would come from a simple table:

    A
    1 DistList
    2 rasleyd@schwebels.com
    3 rasleyd@schwebels.com

    I plan to use a little macro to refresh the range, so as addresses are added or removed the range will auto-correct:


    Sub macSetAddressRange()
    Range(“A1”).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.CreateNames Top:=True, Left:=False, Bottom:=False, Right:=False
    Range(“A1”).Select
    End Sub

    The next part just doesn’t work. The code reads the range and can string together the addresses, but the sendmail command refuses to accept the variable for its recipients parameter.


    Sub macSendMail()
    Module1.macSetAddressRange
    Set Distlist = Sheets(“Sheet1”).Range(“DistList”)
    For Each Address In Distlist
    DistArray = DistArray & Chr(34) & “,” & Chr(34) & Address
    Next
    DistArray = Right(DistArray, Len(DistArray) – 3)
    ActiveWorkbook.SendMail Recipients:=Array(DistArray)
    End Sub

    Can this concept work?

    Viewing 1 reply thread
    Author
    Replies
    • #1048220

      Try this:

          Dim varRecipients
          varRecipients = Sheets("Sheet1").Range("DistList")
          ActiveWorkbook.SendMail Recipients:=varRecipients
      

      HTH

    • #1048226

      You can use a dynamic named range instead of using code to update a fixed named range. See (for example) Named Ranges on Chip Pearson’s site.

    Viewing 1 reply thread
    Reply To: Create mailing list address array (Excel 2k VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: