2017-09-26 3 views
-1

Excel vba를 사용하여받는 사람 목록에 선택한 데이터를 전자 메일로 보내려고합니다.Excel 수신자 목록에 Outlook 전자 메일 보내기

예 :
A 열 시간
열 B 비율
열 C 전체
열 D 이메일 주소

우리는 주간에 발송하는 그들의 지불 세부 수백명의 사람들의 목록을 가지고 기초. Excel 파일의 정보를 복사하여 Outlook 전자 메일에 붙여 넣습니다.

Excel VBA로 이메일을 보내는 방법이 있습니까?

+0

안녕 및 스택 오버플로에 오신 것을 환영합니다! 이것은 매우 광범위한 질문입니다. 너 뭐 벌써 해봤 니? – Chilangosta

답변

1

올바른 방향으로 시작하는 데 도움이됩니다.

Sub SendEmail() 

    Dim OutApp As Object, OutMail As Object 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    With OutMail 
     .To = 'Your Contact List 
     .CC = "" 
     .BCC = "" 
     .Subject = "Your Subject Name" 
     .HTMLBody = 'The email body 
     .Display 
    End With 

End Sub 
1
In column A : Names of the people 
In column B : E-mail addresses 
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files) 

"시트 1"의 각 행을 통해 그리고 매크로 뜻 루프 열 C의 열 B 와 파일명 (S)에서의 E-mail 주소가있는 경우 : Z는이 메일을 작성 윌 이 정보를 가지고 보내십시오.

Sub Send_Files() 
'Working in Excel 2000-2016 
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm 
    Dim OutApp As Object 
    Dim OutMail As Object 
    Dim sh As Worksheet 
    Dim cell As Range 
    Dim FileCell As Range 
    Dim rng As Range 

    With Application 
     .EnableEvents = False 
     .ScreenUpdating = False 
    End With 

    Set sh = Sheets("Sheet1") 

    Set OutApp = CreateObject("Outlook.Application") 

    For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants) 

     'Enter the path/file names in the C:Z column in each row 
     Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1") 

     If cell.Value Like "?*@?*.?*" And _ 
      Application.WorksheetFunction.CountA(rng) > 0 Then 
      Set OutMail = OutApp.CreateItem(0) 

      With OutMail 
       .to = cell.Value 
       .Subject = "Testfile" 
       .Body = "Hi " & cell.Offset(0, -1).Value 

       For Each FileCell In rng.SpecialCells(xlCellTypeConstants) 
        If Trim(FileCell) <> "" Then 
         If Dir(FileCell.Value) <> "" Then 
          .Attachments.Add FileCell.Value 
         End If 
        End If 
       Next FileCell 

       .Send 'Or use .Display 
      End With 

      Set OutMail = Nothing 
     End If 
    Next cell 

    Set OutApp = Nothing 
    With Application 
     .EnableEvents = True 
     .ScreenUpdating = True 
    End With 
End Sub 

https://www.rondebruin.nl/win/s1/outlook/amail6.htm

관련 문제