+ Reply to Thread
Results 1 to 6 of 6

Thread: Email Column C to Column A with Column B as subject

  1. #1
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Email Column C to Column A with Column B as subject

    I just spent 2 hours wading through Ron's pages and the many many posts in this forum. I can't figure out how to simplify Ron's and tailor it to my needs which are simple. I just need to be able to send an email from excel with the following specs. Column A is the user names, Column B is the Subject, column C is the body, and each row should be a different email.
    E.G.

    ColumnA.................ColumnB.................ColumnC
    auser.............size of your share...........Your share is this size. Too big.
    buser.............size of your share...........Your share is this much smaller. thankyou
    ETC...

    I don't need filters or anything like that. I feel like this should be easy but we never covered this type of thing in my scripting class. Thanks for any help you can give. (Even if it is just a link to something I can use.) Oh and I am using Excel and Outlook 07, and all users are on network, so the actual email address shouldn't be needed.

    Thanks again
    Last edited by zkit18; 06-03-2010 at 11:03 AM. Reason: Marked as solved

  2. #2
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Email Column C to Column A with Column B as subject

    Oh, I have about 200 users and It would be great if it would compose all emails and send them automatically when I clicked one button. Thanks.

  3. #3
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Email Column C to Column A with Column B as subject

    I have added the code below as a module to my workbook but I can't figure out cow to add it. I create a button and try to assign a macro to it but it doesn't see the macro I created. Can anyone help me figure out what I am doing wrong? I can't even test this code to see if it will work. Thanks.

    Private Sub CommandButton1_Click()
    
      Dim Cell As Range
      Dim EmailBody As String
      Dim EmailRng As Range
      Dim EmailSubj As String
      Dim EmailTo As String
      Dim olApp As Object
      Dim olEmail As Object
      Dim RngEnd As Range
      Dim Wks As Worksheet
      Dim Row As String
      Row = 1
      
        Set Wks = ActiveSheet
        
        Set EmailRng = Wks.Range("O1")
        Set RngEnd = Wks.Cells(Rows.Count, EmailRng.Column).End(xlUp)
        Set EmailRng = Wks.Range(EmailRng, RngEnd).Resize(ColumnSize:=3)
        
        Do Until Row = 200
          EmailTo = Wks.Cells(Row, 1)
          EmailSubj = Wks.Cells(Row, 2)
          EmailBody = Wks.Cells(Row, 3)
          Row = Row + 1
          Set EmailRng = EmailRng.Find(EmailTo, , xlValues, xlWhole, xlByRows, xlNext, False)
                                      
            If Not EmailRng Is Nothing Then
               EmailTo = EmailRng.Offset(0, 1)
            Else
               MsgBox "Email ID '" & EmailTo & " not found."
               Exit Sub
            End If
          
            Set olApp = CreateObject("Outlook.Application")
            Set olEmail = olApp.CreateItem(0)
            
            With olEmail
              .To = EmailTo
              .Subject = EmailSubj
              .Body = EmailBody
              .Display
            End With
        Loop
        Set olApp = Nothing
        Set olEmail = Nothing
    
    End Sub
    Last edited by zkit18; 06-03-2010 at 09:55 AM. Reason: Updated code

  4. #4
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Email Column C to Column A with Column B as subject

    Ok I got the button linked to the macro. Can anyone help me debug the code?

  5. #5
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Email Column C to Column A with Column B as subject

    I've got it working except it keeps saying email ID not found.
    Last edited by zkit18; 06-03-2010 at 09:46 AM.

  6. #6
    Registered User
    Join Date
    05-06-2010
    Location
    london, ontario
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Email Column C to Column A with Column B as subject

    Thanks for all your help. I got it to work. Here is my end code.


    Private Sub CommandButton1_Click()
    
      Dim Cell As Range
      Dim EmailBody As String
      Dim EmailRng As Range
      Dim EmailSubj As String
      Dim EmailTo As String
      Dim olApp As Object
      Dim olEmail As Object
      Dim RngEnd As Range
      Dim Wks As Worksheet
      Dim Row As String
      Row = 1
      
        Set Wks = ActiveSheet
        
        Do Until Row = -1
          EmailTo = Wks.Cells(Row, "A")
          EmailSubj = Wks.Cells(Row, "B")
          EmailBody = Wks.Cells(Row, "C")
          Row = Row + 1
          If EmailTo = "" Then
            Row = -1
            Exit Sub
          End If
          
            Set olApp = CreateObject("Outlook.Application")
            Set olEmail = olApp.CreateItem(0)
            
            With olEmail
              .To = EmailTo
              .Subject = EmailSubj
              .Body = EmailBody
              .Send
            End With
        Loop
        Set olApp = Nothing
        Set olEmail = Nothing
    
    End Sub
    Last edited by zkit18; 06-03-2010 at 11:02 AM. Reason: Put code in properly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0