Results 1 to 6 of 6

Thread: [RESOLVED] VBA macro to send bulk email

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    14

    Resolved [RESOLVED] VBA macro to send bulk email

    I need help.

    I have a spreadsheet that has multiple columns, 3 of which contain names, email addresses and a column for "confirmed". for simplicity call them A:C

    I am trying to create a macro that will open a userform.
    The form has two text boxes like an emial.

    1. is labled subject
    2. is labled body (side question...how do I allow for the "enter" key to be used in a text box to create more than 1 line?)

    There are two cmd buttons
    1. Cancel (obvioulsy if the user wants to exit without sending)
    2. Send

    Once the send button is clicked on......

    It will take the values from the two text boxes and use them to send a bulk email to everyone on the list who has an email entered, but doesn't have an "X" in the confirmed column.

    This is the code I have for the emial part

    VB Code:
    1. Sub Mail_small_Text_Outlook()
    2. 'You must add a reference to the Microsoft outlook Library
    3.     Dim OutApp As Outlook.Application
    4.     Dim OutMail As Outlook.MailItem
    5.     Dim VarBody As String
    6.     Dim VarSubj As String
    7.     VarSubj = "Userform1.txtSubj.text"
    8.     VarBody = "Userform1.txtBody.text"
    9.     Do
    10.     If ActiveCell <> "" And ActiveCell.Offset(0, 1) <> "X" Then
    11.     Set OutApp = CreateObject("Outlook.Application")
    12.     Set OutMail = OutApp.CreateItem(olMailItem)
    13.     strbody = VarBody
    14.  
    15.     With OutMail
    16.         .To = ActiveCell.Value
    17.         .CC = ""
    18.         .BCC = ""
    19.         .Subject = VarSubj
    20.         .Body = VarBody
    21.         .Send   'or use .Display
    22.     End With
    23.  
    24.     Set OutMail = Nothing
    25.     Set OutApp = Nothing
    26.     ActiveCell.Offset(0, 1) = "X"
    27.     Else: ActiveCell.Offset(1, 0).Select
    28.     End If
    29.     Loop Until ActiveCell.Value = "send_email_end"
    30. End Sub

    I need big help on the code for the userform.

    Thanks so much

  2. #2
    Junior Member
    Join Date
    Sep 2005
    Posts
    20

    Re: VBA macro to send bulk email

    Hi I am not really sure of where u have the trouble..looks like u want to open up the form frm excel sheet..

    u can have a command button next to the 3 cols tht u have on the spreadsheet and code it to open up the userform userform1.show from there u can take it further..

    if u have some trouble with sending the mails do let me know..

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA macro to send bulk email

    Quote Originally Posted by ROB IN RWC
    2. is labled body (side question...how do I allow for the "enter" key to be used in a text box to create more than 1 line?)
    Set both the MultiLine property and the EnterKeyBehavior property of the textbox to TRUE.


    As for showing the form. Here's some sample code. In this sample I have assumed that the form is called UserForm1. You will need to change that to the name of your form.
    VB Code:
    1. Sub SampleShowForm()
    2. Dim fMailForm As UserForm1
    3.    
    4.     'Create a new instance of Userform1
    5.     Set fMailForm = New UserForm1
    6.    
    7.     'Show the form
    8.     fMailForm.Show
    9.    
    10.     'Other code here
    11.    
    12.    
    13.     'Remove the instance when processing is complete
    14.     Set fMailForm = Nothing
    15. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: VBA macro to send bulk email

    I hope this isn't for spamming.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    14

    Re: VBA macro to send bulk email

    No it's not for spamming. It's for a committe that I am on. I need to send emails to confirm times that postions start. I want to be able to send a reminder email to everyone at once that I hadn't previous send one to.

    I've got it to work except for a couple of issues thanks to Kenny's help.

    VB Code:
    1. Option Explicit
    2. Sub SampleShowForm()
    3. Dim fMailForm As frmEmail
    4.    
    5.     'Create a new instance of Userform1
    6.     Set fMailForm = New frmEmail
    7.    
    8.     'Show the form
    9.     fMailForm.Show
    10.    
    11.     'Other code here
    12.     'You must add a reference to the Microsoft outlook Library
    13.     Dim OutApp As Outlook.Application
    14.     Dim OutMail As Outlook.MailItem
    15.     Range("e2").Select
    16.     Do
    17.     If ActiveCell.Value <> "" And ActiveCell.Offset(0, 2).Value <> "X" Then
    18.     Set OutApp = CreateObject("Outlook.Application")
    19.     Set OutMail = OutApp.CreateItem(olMailItem)
    20.     With OutMail
    21.         .To = ActiveCell.Value
    22.         .CC = ""
    23.         .BCC = ""
    24.         .Subject = frmEmail.varSubj
    25.         .Body = frmEmail.varBody
    26.         .Send   'or use .Display
    27.     End With
    28.  
    29.     Set OutMail = Nothing
    30.     Set OutApp = Nothing
    31.     ActiveCell.Offset(0, 2) = "X"
    32.     ActiveCell.Offset(1, 0).Select
    33.     Else: ActiveCell.Offset(1, 0).Select
    34.     End If
    35.     Loop Until ActiveCell.Offset(0, -3).Value = ""
    36.    
    37.     'Remove the instance when processing is complete
    38.     Set fMailForm = Nothing
    39. End Sub

    In this code, I am attempting to call the code from this form...

    VB Code:
    1. Option Explicit
    2. Public varSubj As String
    3. Public varBody As String
    4.  
    5. Private Sub cmdCancel_Click()
    6. Unload Me
    7. End Sub
    8. Private Sub cmdEmail_Click()
    9. varSubj = frmEmail.txtSubj.Text
    10. varBody = frmEmail.txtBody.Text
    11. Me.Hide
    12. End Sub

    Two issues...
    1. There are two text boxes. One for the subject and one for the body of the email. I defined them by using a public variable but it didn't seem to work when I tried to call them. I want the emails that are generated to use the same subject and body. Also, there is a cmdSend button and a cmdCancel button.

    2. The test for whether an email has been sent previosly is to check the cell two columns to the right for an "X". It works perfectly, except when I hit the cancel button. It runs the remainder of the routine anyway.

    Help!!

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    14

    Re: VBA macro to send bulk email

    Just an FYI, I figured this one out!
    I'm proud of me.

Posting Permissions

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



Click Here to Expand Forum to Full Width