Consulting

Results 1 to 9 of 9

Thread: Array of Email Addresses

  1. #1
    VBAX Regular
    Joined
    Nov 2011
    Location
    Houston, TX
    Posts
    27
    Location

    Unhappy Array of Email Addresses

    Greetings,


    I have created a workbook that, among other things, will send an email to other engineers in the region to request equipment needed for an upcoming job. Most of it works, except the Array.


    I have a page in the workbook called "Lists". On this page is a column that contains the names, email addresses, and phone numbers of the other engineers in the region. However, not all regions have 20 engineers, so sometimes the list will not be complete.


    The problem is two-fold:

    First, how do you account for the blank cells in the array?


    Second, how do I actually copy the data into the RegionalEmail variable?


    Here is my code so far.


    Sub EquipmentRequestEmail()
    'Sends an email to all regional Field Engineers to request equipment.
    
    
        Dim CellsToCheck As Variant
        Dim cll As Variant
        Dim RegionalEmail As String
        Dim strSubject As String
        Dim strBody As String
        Dim objApp As Object
        Dim objMail As Object
    
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
    
        With ActiveWorkbook.Worksheets("Lists")
        
        CellsToCheck = Array("J22", "J26", "J30", "J34", "J38", "J42", "J46", "J50", "J54", "J58", "J62", "J66", "J70", "J74", "J78", "J82", "J86", "J90", "J94")
    
    
        For Each cll In CellsToCheck
            With .Range(cll)
                .Copy
            End With
    
    
        Next cll
    
    
        End With
    
    
        RegionalEmail = CellsToCheck
        
        strSubject = "Equipment Request"
    
    
        Set objApp = CreateObject("Outlook.Application")
        Set objMail = objApp.CreateItem(0)
        
        On Error Resume Next
        With objMail
            .To = RegionalEmail
            .Subject = strSubject
            .Body = "Guys," & vbNewLine & vbNewLine & vbTab & "I need a (Insert Equipment Here) for next week please." & vbNewLine & vbNewLine
            .Display
        End With
        On Error GoTo 0
        
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
    
    
    
        Set objMail = Nothing
        Set objApp = Nothing
    
    
    End Sub

    Thanks in advance.
    Dragon

    "You don't need to take a person's advice to make them feel good; just ask for it." ~ Laurence J. Peter

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    post your wrkbook pls. so we can see the info in cells and table structure.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Nov 2011
    Location
    Houston, TX
    Posts
    27
    Location
    My workbook is too large to upload.

    The info in the cells will be email addresses.

    The table structure is simply column J, every 4 rows, the actual numbers are in the array sample I posted.

    I know the array looks at the correct data. What I don't know is how to make it use that data to create the "To" email address and to ignore any cells that are blank.
    Dragon

    "You don't need to take a person's advice to make them feel good; just ask for it." ~ Laurence J. Peter

  4. #4
    VBAX Regular
    Joined
    Nov 2011
    Location
    Houston, TX
    Posts
    27
    Location
    Does anyone have any ideas on this?

    I'm thinking the output from the array could simply be the list of email addresses (i.e. email1@email.com, email2@email.com, email3@email.com, etc.). But when the array finds a cell that is blank, it stops and simply makes the list from the addresses it found. That way there are not a bunch of blanks with commas after the last email address.

    I just don't know how to make that happen.

    Thanks.
    Dragon

    "You don't need to take a person's advice to make them feel good; just ask for it." ~ Laurence J. Peter

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Post a workbook with everything that is not needed to show the problem removed: sheets, columns, etc.

    If the array contains data from blank cells, then I'd say it is NOT looking at the correct data
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Never use copied VBA Code you don't fully understand.

    This is all you need:
    Sub M_snb()
      with CreateObject("Outlook.Application").CreateItem(0)
        .To = join(filter([transpose(Lists!J22:J94)],"@"),",")
        .Subject = "Equipment Request"
        .Body = replace("Guys,##" & vbTab & "I need a (Insert Equipment Here) for next week please.##","#",vblf)
        .Send
      End With
    End Sub

  7. #7
    VBAX Regular
    Joined
    Nov 2011
    Location
    Houston, TX
    Posts
    27
    Location
    I finally was able to try this out and it worked great. I did make a few minor changes so naming conventions and such matched the rest of my code. However, the process is exactly what I needed.

    Thank you.
    Dragon

    "You don't need to take a person's advice to make them feel good; just ask for it." ~ Laurence J. Peter

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Naming conventions in a code that doesn't contain any variables ?

  9. #9
    VBAX Regular
    Joined
    Nov 2011
    Location
    Houston, TX
    Posts
    27
    Location
    I know you didn't put variables in here, but I modified it because I'll be using the same concept in other parts of my workbook (and possibly other workbooks) and I do use variables. Basically, I attach this part to a variable:
    join(filter([transpose(Lists!J22:J94)],"@"),",")
    That way I can include two separate lists of email addresses. One that will be just to the other engineers, and one that will include the office personnel.

    It still works beautifully, thanks again.
    Dragon

    "You don't need to take a person's advice to make them feel good; just ask for it." ~ Laurence J. Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •