Skicka e-post till flera mottagare

 

Här i detta exempel visas hur vi kan skicka e-post till en grupp av mottagare. Denna grupps e-postadresser återfinns i ett cellområde.

Här använder vi oss av "early binding" varför vi måste sätta en referens till MS Outlook Object Library x.x via Verktyg | Referenser... i VB-editorn.

Option Explicit

 Sub Skicka_Arbetsblad_Outlook()

   '© 2003 Alla rättigheter XL-Dennis

   Dim wbBok As Workbook

   Dim wsBlad As Worksheet

   Dim rnMottagare As Range

   Dim vaMottagare As Variant

   Dim i As Long

   Dim olApp As Outlook.Application

   Dim olNewMail As Outlook.MailItem

 

   Set olApp = New Outlook.Application

   Set olNewMail = CreateItem(olMailItem)

 

   Set wbBok = ThisWorkbook

   Set wsBlad = wbBok.Worksheets("Blad1")

 

   With wsBlad

      Set rnMottagare = .Range("Addreser")

   End With

 

   vaMottagare = rnMottagare.Value

 

   With olNewMail

      'Här lägger vi samtliga e-postmottagare och särskiljer

      'dessa med semikolon.

      For i = LBound(vaMottagare) To UBound(vaMottagare)

         .Recipients.Add (vaMottagare(i, 1) & ";")

      Next i

      .CC = "Team 2000"

      .BCC = "Evaluering"

      .Subject = "Ärende: Programlista"

      .Body = "Enligt överenskommelse."

      With .Attachments

         .Add ThisWorkbook.Path & "\" & ThisWorkbook.Name

         .Item(1).DisplayName = "Sända e-post"

      End With

      .Save

      .Display

   End With

 

   Set olNewMail = Nothing

   Set olApp = Nothing

End Sub