메인 컨텐츠로 가기

Excel에서 각 시트를 다른 이메일 주소로 보내는 방법은 무엇입니까?

여러 워크시트가 있는 통합 문서가 있고 각 시트의 A1 셀에 이메일 주소가 있는 경우. 이제 통합 문서의 각 시트를 A1 셀의 해당 받는 사람에게 개별적으로 첨부 파일로 보내려고 합니다. Excel에서 이 작업을 어떻게 해결할 수 있습니까? 이 기사에서는 Excel의 다른 이메일 주소에 각 시트를 첨부 파일로 보내는 VBA 코드를 소개합니다.


VBA 코드를 사용하여 Excel에서 각 시트를 다른 이메일 주소로 보내기

다음 VBA 코드는 각 시트를 다른 수신자에게 첨부 파일로 보내는 데 도움이 될 수 있습니다. 다음과 같이 하십시오.

1. 프레스 Alt + F11 동시에 열려면 키 응용 프로그램 용 Microsoft Visual Basic 창.

2. 그런 다음 끼워 넣다 > 모듈, 아래 VBA 코드를 복사하여 창에 붙여넣습니다.

VBA 코드: 각 시트를 다른 이메일 주소에 첨부 파일로 보내기

Sub Mail_Every_Worksheet()
'Updateby ExtendOffice
  Dim xWs As Worksheet
  Dim xWb As Workbook
  Dim xFileExt As String
  Dim xFileFormatNum As Long
  Dim xTempFilePath As String
  Dim xFileName As String
  Dim xOlApp As Object
  Dim xMailObj As Object
  On Error Resume Next
  With Application
      .ScreenUpdating = False
      .EnableEvents = False
  End With
  xTempFilePath = Environ$("temp") & "\"
  If Val(Application.Version) < 12 Then
    xFileExt = ".xls": xFileFormatNum = -4143
  Else
    xFileExt = ".xlsm": xFileFormatNum = 52
  End If
  Set xOlApp = CreateObject("Outlook.Application")
  For Each xWs In ThisWorkbook.Worksheets
    If xWs.Range("S1").Value Like "?*@?*.?*" Then
      xWs.Copy
      Set xWb = ActiveWorkbook
      xFileName = xWs.Name & " of " _
                   & VBA.Left(ThisWorkbook.Name, VBA.InStr(ThisWorkbook.Name, ".") - 1) & " "
      Set xMailObj = xOlApp.CreateItem(0)
      xWb.Sheets.Item(1).Range("S1").Value = ""
      With xWb
        .SaveAs xTempFilePath & xFileName & xFileExt, FileFormat:=xFileFormatNum
        With xMailObj
        'specify the CC, BCC, Subject, Body below
            .To = xWs.Range("S1").Value
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Hi there"
            .Attachments.Add xWb.FullName
            .Display
        End With
        .Close SaveChanges:=False
      End With
      Set xMailObj = Nothing
      Kill xTempFilePath & xFileName & xFileExt
    End If
  Next
  Set xOlApp = Nothing
  With Application
      .ScreenUpdating = True
      .EnableEvents = True
  End With
End Sub
주의 사항: 위 코드에서 :
  • S1 셀에는 이메일을 보낼 이메일 주소가 포함되어 있습니다. 필요에 따라 변경하십시오.
  • 코드에서 CC, BCC, 제목, 본문을 고유하게 지정할 수 있습니다.
  • 다음 새 메시지 창을 열지 않고 이메일을 직접 보내려면 다음을 변경해야 합니다. .디스플레이.보내다.

3. 그런 다음, F5 키를 눌러 이 코드를 실행하고 각 시트는 새 메시지 창에 자동으로 첨부 파일로 삽입됩니다. 스크린샷 참조:

4. 마지막으로 클릭만 하면 됩니다. 전송 버튼을 눌러 각 이메일을 하나씩 보냅니다.

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Does anyone know how to do this exactly but attach Files as PDF Is there an add on code that will convert the Excel to PDF to send via email as well at all. I tried changing the File EXT to .PDF instead of . XLS and .XLSM it attaches a File as PDF but doesn't open the PDF as a recognised File

thanks
This comment was minimized by the moderator on the site
Hello, Jo,
To send the attach files as PDF , please apply the following code:
Sub Mail_Every_Worksheet_As_PDF()
    'Updated by ExtendOffice to send each worksheet as a PDF
    Dim xWs As Worksheet
    Dim xTempFilePath As String
    Dim xFileName As String
    Dim xOlApp As Object
    Dim xMailObj As Object
    On Error Resume Next
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    xTempFilePath = Environ$("temp") & "\"
    Set xOlApp = CreateObject("Outlook.Application")
    For Each xWs In ThisWorkbook.Worksheets
        If xWs.Range("A1").Value Like "?*@?*.?*" Then
            xFileName = xWs.Name & " of " _
                         & VBA.Left(ThisWorkbook.Name, VBA.InStr(ThisWorkbook.Name, ".") - 1)
            xWs.Copy
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xTempFilePath & xFileName & ".pdf", Quality:=xlQualityStandard
            
            Set xMailObj = xOlApp.CreateItem(0)
            With xMailObj
                'specify the CC, BCC, Subject, Body below
                .To = xWs.Range("A1").Value
                .CC = ""
                .BCC = ""
                .Subject = "This is the Subject line"
                .Body = "Hi there"
                .Attachments.Add xTempFilePath & xFileName & ".pdf"
                .Display
            End With
            ActiveWorkbook.Close SaveChanges:=False
            Kill xTempFilePath & xFileName & ".pdf"
            Set xMailObj = Nothing
        End If
    Next
    Set xOlApp = Nothing
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub


Please have a try, Hope this can help you!
This comment was minimized by the moderator on the site
This works perfectly thanks so much
This comment was minimized by the moderator on the site
This works well, just what i was needing. Is there an add on code that will convert the Excel to PDF to send via email as well at all.

thanks
This comment was minimized by the moderator on the site
This is awesome! Thanks for this code!

Only thing I'd like, is there a way to copy values instead of links in the sheets?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations