+ Reply to Thread
Results 1 to 2 of 2

Sending emails from excel using VBA

  1. #1
    Registered User
    Join Date
    06-29-2015
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2013
    Posts
    7

    Lightbulb Sending emails from excel using VBA

    Hey,
    I am having difficulties with putting a VBA code together. The code should send personalized emails taking data from different excel cells. I also need a greeting line such as Hello! and beginning line such as "Here is the overview of the used service:" and after that VBA code should take only needed data for every company. And end with "Best wishes, etc".
    My excel table looks something like this, email addresses and company are duplicates so it would be nice if the code knew to take only what belongs to certain company:

    Period Number Provider Service Count Duration Total Email
    201504 12345 ETV Phone 3 13 32 [email protected]
    201504 54321 ETV Phone 2 12 23 [email protected]
    201504 98765 Tallink Phone 8 18 98 [email protected]
    201504 56789 Tallink Phone 7 17 71 [email protected]


    Final product should look like this:
    First email
    to [email protected]
    Hello!
    Here is the overview of the used service:
    Period / Number / Provider / Count / Duration /
    201504 / 900654 / ETV / 5 / 89 /
    201504 / 900098 / ETV / 2 / 24 /
    Best wishes,
    My Name
    *Signature preferably

    Second email
    to [email protected]
    Hello!
    Here is the overview of the used service:
    Period / Number / Provider / Count / Duration /
    201504 / 354864 / Tele2 / 7 / 64/
    201504 / 354864 / Tele2 / 7 / 64/
    Best wishes,
    My Name
    *Signature preferably

    ETC.

    This email needs to be sent in the beginning of every month. There are about 13-15 different emails - so 13-15 letters to be sent.
    Any ideas?
    Code that i found is provided in the comments, but it gives me this: Compile error: User-defined type not defined. Sub Mail_To_Friends() gets colored yellow.

  2. #2
    Registered User
    Join Date
    06-29-2015
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Sending emails from excel using VBA

    Code that i found looks like this:


    Sub Mail_To_Friends()
    'Below Loop can be changed to While Loop or increase the limit (10) if your list has more than 10 mail ids
    Dim SendTo As String
    Dim ToMSg As String

    For i = 1 To 10
    SendTo = ThisWorkbook.Sheets(1).Cells(i, 1)
    If SendTo <> “” Then
    ToMSg = ThisWorkbook.Sheets(1).Cells(i, 3)
    Send_Mail SendTo, ToMSg
    End If
    Next i
    End Sub
    Sub Send_Mail(SendTo As String, ToMSg As String)
    Dim OutlookApp As Object
    Dim OutlookMail As Object

    Set OutlookApp = CreateObject(“Outlook.Application”)
    Set OutlookMail = OutlookApp.CreateItem(0)

    With OutlookMail
    .to = SendTo
    .CC = “”
    .BCC = “”
    .Subject = “Happy New Year”
    .Body = ToMSg
    .Display ' or just put .Send to directly send the mail instead of display
    End With

    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
    End Sub



    I have added few lines:

    Dim Valitud As String
    Dim Pakkuja As String
    Dim Arv As String
    Dim Kestvus As String

    Valitud = ThisWorkbook.Sheets(3).Cells(i, 2)
    Pakkuja = ThisWorkbook.Sheets(3).Cells(i, 3)
    Arv = ThisWorkbook.Sheets(3).Cells(i, 4)
    Kestvus = ThisWorkbook.Sheets(3).Cells(i, 5)
    ToMSg = Valitud & Pakkuja & Arv & Kestvus 'This line should add up previous Strings - however i do not know if it does, because i cannot run the code

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sending Emails Using Excel & VBA
    By dthennessy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2014, 04:07 AM
  2. [SOLVED] Sending emails from excel
    By TraceyQld in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2014, 04:10 AM
  3. [SOLVED] Sending Outlook emails from Excel; Limits to three emails only?
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2013, 06:53 AM
  4. Sending macro emails using excel: Send emails with their passwords.
    By loveisblind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 03:16 PM
  5. Help Sending Emails From Excel
    By mrk0 in forum Excel General
    Replies: 1
    Last Post: 07-06-2005, 02:05 PM

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