Gửi mail hàng loạt có đính kèm file riêng lẻ

Liên hệ QC

Monkey1508

Thành viên mới
Tham gia
24/2/21
Bài viết
13
Được thích
0
Em chào Anh/Chị,
Nhờ Anh/Chị, hỗ trợ giúp em cách gửi email hàng loạt có đính kèm file riêng lẻ ạ.
Em có đính kèm file bên dưới, tuy nhiên file này chỉ chạy ra đúng 1 email nhưng em đang cần gửi đến từng email với từng file khác nhau.
Em cảm ơn Anh/Chị nhiều ạ
 

File đính kèm

  • Gui mail.xlsm
    50.6 KB · Đọc: 55
Trong code bài #17
thay
Mã:
.body = Sh.Range("F" & i).Value

bằng
Mã:
.Display
.body = Sh.Range("F" & i).Value & .body
Vâng mình cảm ơn. Tuy nhiên, chữ ký chỉ hiện dạng text thôi ạ. Các hình ảnh trong chữ ký thì không hiện. Có cách nào lấy full chữ ký như outlook không ạ?
 
Upvote 0
Vâng mình cảm ơn. Tuy nhiên, chữ ký chỉ hiện dạng text thôi ạ. Các hình ảnh trong chữ ký thì không hiện. Có cách nào lấy full chữ ký như outlook không ạ?
Bạn tham khảo link này nhé. Hướng dẫn chi tiết

Display Outlook Signature

Mã:
Sub With_HTML_Signature_With_Image()

    'Do not forget to change the email ID
    'before running this code

    Dim OlApp As Object
    Dim NewMail As Object
    Dim EmailBody As String
    Dim StrSignature As String
    Dim sPath As String
    Dim signImageFolderName As String
    Dim completeFolderPath As String

    Set OlApp = CreateObject("Outlook.Application")
    Set NewMail = OlApp.CreateItem(0)

    ' Here Since we are talking about
    ' the HTML email then we need to
    ' write the Body of the Email in
    ' HTML.

    EmailBody = "Hello Friends !!" & "

Welcome to LearnExcelMacro.com" & vbNewLine & _
    "Here i will make you awesome in Excel Macro.

You can mail me at info@learnexcelmacro.com"

    '*****************************************************
    '                    Important
    '*****************************************************
    ' go to the appdata path as mentioned in
    ' the above important point. Check the name of
    ' the signature file. For example: here in my system
    ' the signature's file name is vish.txt, vish.htm
    ' Therefore before running this code, check the
    ' name of the signature file in your system and
    ' replace vish.txt with your file name.
    '****************************************************

    sPath = Environ("appdata") & "\Microsoft\Signatures\Default.htm"
    ' Files folder name is always same name as html file name appended by
    ' "_files"
    signImageFolderName = "Default_files"
    ' in outlook HTML forward slashes are used for
    ' the file path
    completeFolderPath = Environ("appdata") & "\Microsoft\Signatures\" & signImageFolderName

    ' If the path and file name given by you is not
    ' correct then code you insert a blank Signature

    If Dir(sPath) <> "" Then
        StrSignature = GetSignature(sPath)
        ' Now replace this incomplete file path
        ' with complete path wherever it is used
        StrSignature = VBA.Replace(StrSignature, signImageFolderName, completeFolderPath)
    Else
        StrSignature = ""
    End If

    On Error Resume Next
    With NewMail
        .To = "info@learnexcelmacro.com"
        .CC = "info@learnexcelmacro.com"
        .BCC = "info@learnexcelmacro.com"
        .Subject = "Type your Subject here"
        ' Here at the end of the Email Body
        ' HTML Signature is inserted.
        .htmlBody = EmailBody & StrSignature
        .display
        .send
    End With
    On Error GoTo 0
    Set NeMail = Nothing
    Set OlApp = Nothing
End Sub

Function GetSignature(fPath As String) As String
    Dim fso As Object
    Dim TSet As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)
    GetSignature= TSet.readall
    TSet.Close
End Function
 
Upvote 0
Bạn tham khảo link này nhé. Hướng dẫn chi tiết

Display Outlook Signature

Mã:
Sub With_HTML_Signature_With_Image()

    'Do not forget to change the email ID
    'before running this code

    Dim OlApp As Object
    Dim NewMail As Object
    Dim EmailBody As String
    Dim StrSignature As String
    Dim sPath As String
    Dim signImageFolderName As String
    Dim completeFolderPath As String

    Set OlApp = CreateObject("Outlook.Application")
    Set NewMail = OlApp.CreateItem(0)

    ' Here Since we are talking about
    ' the HTML email then we need to
    ' write the Body of the Email in
    ' HTML.

    EmailBody = "Hello Friends !!" & "

Welcome to LearnExcelMacro.com" & vbNewLine & _
    "Here i will make you awesome in Excel Macro.

You can mail me at info@learnexcelmacro.com"

    '*****************************************************
    '                    Important
    '*****************************************************
    ' go to the appdata path as mentioned in
    ' the above important point. Check the name of
    ' the signature file. For example: here in my system
    ' the signature's file name is vish.txt, vish.htm
    ' Therefore before running this code, check the
    ' name of the signature file in your system and
    ' replace vish.txt with your file name.
    '****************************************************

    sPath = Environ("appdata") & "\Microsoft\Signatures\Default.htm"
    ' Files folder name is always same name as html file name appended by
    ' "_files"
    signImageFolderName = "Default_files"
    ' in outlook HTML forward slashes are used for
    ' the file path
    completeFolderPath = Environ("appdata") & "\Microsoft\Signatures\" & signImageFolderName

    ' If the path and file name given by you is not
    ' correct then code you insert a blank Signature

    If Dir(sPath) <> "" Then
        StrSignature = GetSignature(sPath)
        ' Now replace this incomplete file path
        ' with complete path wherever it is used
        StrSignature = VBA.Replace(StrSignature, signImageFolderName, completeFolderPath)
    Else
        StrSignature = ""
    End If

    On Error Resume Next
    With NewMail
        .To = "info@learnexcelmacro.com"
        .CC = "info@learnexcelmacro.com"
        .BCC = "info@learnexcelmacro.com"
        .Subject = "Type your Subject here"
        ' Here at the end of the Email Body
        ' HTML Signature is inserted.
        .htmlBody = EmailBody & StrSignature
        .display
        .send
    End With
    On Error GoTo 0
    Set NeMail = Nothing
    Set OlApp = Nothing
End Sub

Function GetSignature(fPath As String) As String
    Dim fso As Object
    Dim TSet As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set TSet = fso.GetFile(fPath).OpenAsTextStream(1, -2)
    GetSignature= TSet.readall
    TSet.Close
End Function
Sorry mình hơi gà nhưng có thể thêm vào code có sẵn của post #17 không ạ? Hay cái này là code riêng?
Nếu thêm được thì nhờ bạn hướng dẫn mình với.
Cảm ơn.
 
Upvote 0
Vâng mình cảm ơn. Tuy nhiên, chữ ký chỉ hiện dạng text thôi ạ. Các hình ảnh trong chữ ký thì không hiện. Có cách nào lấy full chữ ký như outlook không ạ?
Đó là do bạn dùng BODY. Muốn thư có cả hình ảnh thì phải dùng HTMLBODY. Bạn không nói rõ thì làm sao tôi biết bạn cần ảnh.
Tôi giúp bạn lần cuối.

not_dung_HTML = "..." ' <-- tìm đọc để biết cách tạo nội dung HTML

...
.Display
.HTMLBody = not_dung_HTML & .HTMLBody
 
Upvote 1
bạn sửa lại phần Sub guimail như code dưới đây (phần chữ đỏ):
Mã:
Sub guimail()
Dim OutApp As Object
Dim OutMail As Object
Dim Lr&, i&, Sh As Worksheet
Dim Arr, k&

Set OutApp = CreateObject("Outlook.Application")
Set Sh = Sheets("Sendmail")

Lr = Sh.Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = Sh.Range("B" & i).Value
        .cc = Sh.Range("C" & i).Value
        .BCC = Sh.Range("D" & i).Value
        .Subject = Sh.Range("E" & i).Value
        .body = Sh.Range("F" & i).Value
        Arr = Split(Sh.Range("G" & i).Value, Chr(10))
        For k = 0 To UBound(Arr)
            .Attachments.Add Arr(k)
        Next k
        '.display (xem lại) .send (gui ngay)
        .send
    End With
    Set OutMail = Nothing
Next i
Set OutApp = Nothing
End Sub
Dạ em bị lỗi file đính kèm, giúp e chỗ này với ạ, ban đầu e gửi file pdf được, lúc sau chỉnh sao lại ko gửi đc nữa, e đang rất cần, huhu làm ơn giúp em với ạ :(((( 1641459110144.png
 
Upvote 0
Upvote 0
File bạn làm đâu? có mình mới biết chỉnh chỗ nào ah
Dạ đội ơn anh, đăng lên vậy thôi chứ cũng ko nghĩ là sẽ có ai rep vì nghĩ chắc ko còn ai hoạt động trên này nữa hix. Excel của e bị đơ nãy h nên e chưa gửi lên đc :(( e chưa save, đơ kiểu này có end task khởi động lại thôi mà e ko nỡ, khổ hết biết :((( để e xem một lát nữa có hết đơ ko, ko thì e thao tác lại rồi gửi lên nhờ a check giúp e ạ, cảm ơn anh rất nhiều ạ
 
Upvote 0
File bạn làm đâu? có mình mới biết chỉnh chỗ nào ah
Dạ đội ơn anh, đăng lên vậy thôi chứ cũng ko nghĩ là sẽ có ai rep vì nghĩ chắc ko còn ai hoạt động trên này nữa hix. Excel của e bị đơ nãy h nên e chưa gửi lên đc :(( e chưa save, đơ kiểu này có end task khởi động lại thôi mà e ko nỡ, khổ hết biết :((( để e xem một lát nữa có hết đơ ko, ko thì e thao tác lại rồi gửi lên nhờ a check giúp e ạ, cảm ơn anh rất nhiều
Dạ file của e đây ạ, e lấy file của nickname 13388, check giúp e với nha, e cảm ơn nhiều ạ
 

File đính kèm

  • guimailhangloat (1).xlsm
    22.9 KB · Đọc: 27
Upvote 0
ủa tôi chạy send mail thấy bình thường mà...
E cứ bị báo lỗi như vậy hoài ạ, a có gửi đến mail như trong file e để ko ạ? đó là mail e, e vẫn chưa nhận được mail nào ạ
Bài đã được tự động gộp:

ủa tôi chạy send mail thấy bình thường mà...
Dạ cuối cùng e cũng biết nguyên nhân từ đâu rồi, mà cho e hỏi thêm là e cop nội dung word dán vô thì các định dạng như in đậm lúc gửi bị mất hết, có cách nào để khắc phục vấn đề này không ạ? và làm sao để đính kèm chữ ký vô nữa ạ? Em cảm ơn ạ
 
Lần chỉnh sửa cuối:
Upvote 0
Có vấn đề mà không tò mò đọc các bài khác trong chủ đề à? Có những bài trong chủ đề này nói về đính kèm chữ ký đấy.
Mình đã chèn được chữ ký hình ảnh theo hướng dẫn của bạn nhưng nội dung nó dính liền nhau ạ, mặc dù trong file nội dung mình tách xuống dòng, giúp mình với được k ạ, do mình không rành về VBA ạ :(((, mình muốn nội dung và lấy định dạng in đậm/in màutheo trong file excel luôn ạ
 

File đính kèm

  • HA1.png
    HA1.png
    147.5 KB · Đọc: 11
  • Send Mail Outlook.xlsm
    25.2 KB · Đọc: 8
Lần chỉnh sửa cuối:
Upvote 0
ủa tôi chạy send mail thấy bình thường mà...
Dạ, anh có thể xem giúp em code của file này được không ạ? Em gửi nhiều file đính kèm nhưng có lỗi là gửi cho người thứ 2 sẽ bao gồm file đã gửi cho người thứ nhất luôn, giúp em với ạ, cám ơn anh
 

File đính kèm

  • Gui nhieu file khac nhau cho nhieu nguoi qua email.xlsm
    20.5 KB · Đọc: 8
Upvote 0
Bạn tham khảo thêm bài viết tại đây xem:

 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom