+ Reply to Thread
Results 1 to 2 of 2

macro for sendding mail via outlook and input parameters from excel sheet

Hybrid View

ashayk macro for sendding mail via... 01-25-2011, 01:39 AM
johnjohns Re: macro for sendding mail... 01-25-2011, 02:33 AM
  1. #1
    Registered User
    Join Date
    01-24-2011
    Location
    india
    MS-Off Ver
    Excel 2003
    Posts
    1

    Unhappy macro for sendding mail via outlook and input parameters from excel sheet

    Hello all.
    I am new to this forum and this is my first post, hope i will not get disappointed
    a quick solution cause, email id separator
    Thanks in advance ...

    I am having a macro which send emails to different users via outlook, its working fine.
    an array is build, a loop runs which send different mails depending on the count.
    All the contents like email id's, subject, attachment path are written in an excel workbook.
    Email ID - TO , CC, BCC - are written in excel workbook

    Problem ,
    1) I need to CC the mails to multiple users, and the email address are written in cell "b4"\
    when i am writing single emailid in this cell, it works.
    but when i write muliple email id in cell b4,separated by " ;" or "," it shows runtime error
    " Outlook does not recognise one or more names"

    2) Also, it always ask for permission that a program is sendimg email on your behalf .... asking for allow / dont allow
    i want to remove this manual intervention.

    i am attaching the code along with this email.
    Sub SendMessage()

    Dim i As Integer
    Dim intRowCount As Integer


    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim SendEmailTo, SendEmailCc, SendEmailBcc, SendEmailSub, AttachmentDir, AttachmentFile, attachmentPath As String
    intRowCount = 2
    ' MonthYear = Format(Sheets("Dashboard").Range("S1").Value, "MMM-YYYY")
    SendEmailCc = "emailaddress1;emailaddress2;emailaddress3"
    '<-- Enter the email address here.

    AttachmentDir = Sheets("Sheet2").Range("B1").Value

    For i = 1 To intRowCount

    AttachmentFile = Sheets("Sheet2").Range("d4:d100").Cells(i).Value

    SendEmailTo = Sheets("Sheet2").Range("a4:a100").Cells(i).Value
    SendEmailCc = Sheets("Sheet2").Range("b4:b100").Cells(i).Value
    SendEmailCc = "emailaddress1;emailaddress2"
    SendEmailSub = Sheets("Sheet2").Range("c4:c100").Cells(i).Value
    SendEmailBcc = Sheets("Sheet2").Range("e4:e100").Cells(i).Value

    ' SendEmailSub = "CentreCode " & Sheets("Sheet2").Range("E2").Value

    attachmentPath = AttachmentDir & AttachmentFile




    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
    ' Add the To recipient(s) to the message.


    Set objOutlookRecip = .Recipients.Add(SendEmailTo)
    objOutlookRecip.Type = olTo

    ' Add the CC recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add(SendEmailCc)
    objOutlookRecip.Type = olCC

    ' Add the BCC recipient(s) to the message.
    ' Set objOutlookRecip = .Recipients.Add(SendEmailBcc)
    ' objOutlookRecip.Type = olBCC

    ' Set the Subject, Body, and Importance of the message.
    .Subject = SendEmailSub
    ' .Body = "This is the body of the message." & vbCrLf & vbCrLf
    .Importance = olImportanceHigh 'High importance

    ' Add attachments to the message.
    If Not IsMissing(attachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(attachmentPath)
    End If

    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    Next

    ' Should we display the message before sending?
    If DisplayMsg Then
    .Display
    Else
    .Save
    .Send
    End If
    End With
    Set objOutlook = Nothing

    Next i
    End Sub

  2. #2
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: macro for sendding mail via outlook and input parameters from excel sheet

    Welcome to the forum ashayk. Please read the forum rules. You have to add code tags for you code.
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1