Outlook email using VBA
Results 1 to 4 of 4

Thread: Outlook email using VBA

  1. #1
    New Member
    Join Date
    Dec 2014
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Outlook email using VBA

    Hi all,

    I am current in the process of trying to automatically send emails via outlook from data found in my excel spreadsheet. Here's what I've done so far;

    Code:
    Sub Send_email()
    
       Dim sh As Worksheet
       Set sh = ThisWorkbook.Sheets("email")
        
       Dim Outlook As Object
       Dim msg As Object
        
       Set Outlook = CreateObject("outlook.application")
       
       Dim i As Integer
       Dim last_row As Integer
        
       last_row = Application.WorksheetFunction.CountA(sh.Range("B:B"))
        
       For i = 2 To last_row
       Set msg = Outlook.createitem(0)
        If sh.Range("E" & i) = "" Then
        
       msg.To = sh.Range("B" & i).Value
       msg.bcc = sh.Range("C" & i).Value
       msg.Subject = "Request Status"
       msg.body = "Your request has been"
        
       msg.display
       sh.Range("E" & i).Value = "sent"
        Else
        sh.Range("E" & i) = "Sent"
        End If
        
    Next i
    
    
    MsgBox "Email sent"
    
    
    End Sub
    The above script is working perfectly but im looking to compose the email a bit more in depth. See https://imgur.com/Ko2gRRM for a visual of the table i am currently using for my data



    Code:
      msg.body = "Your request has been"
    I'm looking to reference call D that currently shows the status to appear on the end of the current text (Script above). So the email will read "Your request has been Approved" for example.

    Hope this makes sense and would appreciate any help on this.

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,320
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Outlook email using VBA

    Try this

    Quote Originally Posted by owen4512 View Post
    Hi all,

    I am current in the process of trying to automatically send emails via outlook from data found in my excel spreadsheet. Here's what I've done so far;

    Code:
    Sub Send_email()
    
       Dim sh As Worksheet
       Set sh = ThisWorkbook.Sheets("email")
        
       Dim Outlook As Object
       Dim msg As Object
        
       Set Outlook = CreateObject("outlook.application")
       
       Dim i As Integer
       Dim last_row As Integer
        
       last_row = Application.WorksheetFunction.CountA(sh.Range("B:B"))
        
       For i = 2 To last_row
         Set msg = Outlook.createitem(0)
        If sh.Range("E" & i) = "" Then
        
          msg.To = sh.Range("B" & i).Value
          msg.bcc = sh.Range("C" & i).Value
          msg.Subject = "Request Status"
          msg.body = "Your request has been " & sh.Range("D" & i).value
        
          msg.display
          sh.Range("E" & i).Value = "sent"
       Else
          sh.Range("E" & i) = "Sent"
       End If    
       Next i
      MsgBox "Email sent"
    End Sub
    The above script is working perfectly but im looking to compose the email a bit more in depth. See https://imgur.com/Ko2gRRM for a visual of the table i am currently using for my data



    Code:
      msg.body = "Your request has been"
    I'm looking to reference call D that currently shows the status to appear on the end of the current text (Script above). So the email will read "Your request has been Approved" for example.

    Hope this makes sense and would appreciate any help on this.
    Regards Dante Amor

  3. #3
    New Member
    Join Date
    Dec 2014
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Outlook email using VBA

    That's done it. Thank you

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,320
    Post Thanks / Like
    Mentioned
    50 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Outlook email using VBA

    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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