Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Excel VBA to Attach File And Automatically Send Email

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Excel VBA to Attach File And Automatically Send Email

    Hello,

    I have been using VBA Codes to create Macros. But, with my current scenario i have no idea as how to do it.


    Scenario :- I have to send reports to our Client , with my updated Report (which will be saved on Desktop).

    You can Find Email Address in the Column " AA" in the Report .

    I want the Macro to Run and then to attach file and Also, it should pick " Email address " automatically. If possible, a Pop-up to ask User " do you want to send email".

    Your Help is Much Appreciated.

    Thanks.

    Giri

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNsaS3Lp1
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgR1EPUkhw
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNe_XC-jK
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNPOdiDuv
    https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgN7AC7wAc
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm 9wlhQrYJP3M
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=DVFFApHzYVk&lc=Ugyi578yhj9zShmhuPl4AaABAg
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgxvxlnuTRWiV6MUZB14AaABAg
    https://www.youtube.com/watch?v=_8i1fVEi5WY&lc=Ugz0ptwE5J-2CpX4Lzh4AaABAg
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxoHAw8RwR7VmyVBUt4AaABAg. 9C-br0lEl8V9xI0_6pCaR9
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=Ugz5DDCMqmHLeEjUU8t4AaABAg. 9bl7m03Onql9xI-ar3Z0ME
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgxYnpd9leriPmc8rPd4AaABAg. 9gdrYDocLIm9xI-2ZpVF-q
    https://www.youtube.com/watch?v=0ltJS7uHfK4&lc=UgyjoPLjNeIAOMVH_u94AaABAg. 9id_Q3FO8Lp9xHyeYSuv1I
    https://www.reddit.com/r/windowsxp/comments/pexq9q/comment/k81ybvj/?utm_source=reddit&utm_medium=web2x&context=3
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgxYgiEZuS9I3xkjJv54AaABAg
    https://www.youtube.com/watch?v=bs-urI_o8jo&lc=UgyBACXgNY4j_cHgH5J4AaABAg.9oTkVdzfqfm 9wlhQrYJP3M
    ttps://www.youtube.com/watch?v=LP9fz2DCMBE
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg
    https://www.youtube.com/watch?v=LP9fz2DCMBE&lc=UgzbPgJUMCztIOQDym14AaABAg. 9wdo_rWgxSH9wdpcYqrvp8
    ttps://www.youtube.com/watch?v=bFxnXH4-L1A
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxuODisjo6cvom7O-B4AaABAg.9w_AeS3JiK09wdi2XviwLG
    https://www.youtube.com/watch?v=bFxnXH4-L1A&lc=UgxBU39bTptFznDC1PJ4AaABAg
    ttps://www.youtube.com/watch?v=GqzeFYWjTxI
    https://www.youtube.com/watch?v=GqzeFYWjTxI&lc=UgwJnJDJ5JT8hFvibt14AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 11-20-2023 at 03:43 PM.

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0
    E-Mailing from excel

    hey this is a piece from my refereence file
    it should work pretty well.

    it should all be pretty straight forward to taylor to your needs.

    Code:
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2010
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "Cell A1 is changed" & vbNewLine & _
                  "This is line 2" & vbNewLine & _
                  "This is line 3" & vbNewLine & _
                  "This is line 4"
    
        On Error Resume Next
        With OutMail
            .To = Email@Domain.com		'Email Address (can be a cell reference)
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = strbody 
            '.Attachments.Add ("C:\test.txt") 	'You can add a file like this
            .Display  					 'or use .Send
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    any problems give me a shout =D

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=TW3l7PkSPD4&lc=UgwAL_Jrv7yg7WWC8x14AaABAg
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=Ugz39PGfytiMUCmTPTl4AaABAg. 91d_Pbzklsp9zfGbIr8hgW
    https://www.youtube.com/watch?v=zHJPliWS9FQ&lc=UgwbcybM8fXnaIK-Y3B4AaABAg.97WIeYeaIeh9zfsJvc21iq
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zciSZa959d
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgzTC8V4jCzDHbmfCHF4AaABAg. 9zaUSUoUUYs9zckCo1tvPO
    https://www.youtube.com/watch?v=vSjTzhoJFdk&lc=UgwMsgdKKlhr2YPpxXl4AaABAg
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg. 9xmkXGSciKJ9xonTti2sIx
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg. 9xnskBhPnmb9xoq3mGxu_b
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg. 9xm_ufqOILb9xooIlv5PLY
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG
    https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg. 9xmt8i0IsEr9y3FT9Y9FeM
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 04-11-2024 at 06:21 PM.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0
    oh sorry and the question would go like

    Code:
    if msgbox("Do you want to send an e-mail?",vbQuestion+vbYesNo,"Send Email" ) = vbNo then exit sub
    at the start of the code.

  4. #4
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Forward mails with attachment in excel VBA code

    Quote Originally Posted by Friel300 View Post
    E-Mailing from excel

    hey this is a piece from my refereence file
    it should work pretty well.

    it should all be pretty straight forward to taylor to your needs.

    Code:
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2010
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "Cell A1 is changed" & vbNewLine & _
                  "This is line 2" & vbNewLine & _
                  "This is line 3" & vbNewLine & _
                  "This is line 4"
    
        On Error Resume Next
        With OutMail
            .To = Email@Domain.com		'Email Address (can be a cell reference)
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = strbody 
            '.Attachments.Add ("C:\test.txt") 	'You can add a file like this
            .Display  					 'or use .Send
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    any problems give me a shout =D
    This is quite good but what i need is to forward all mails saved in a folder to a different recipient with the attachments on the mails.I find it difficult to do and the above solution did not serve the purpose as attachments are sent from the hard drive location and not from the saved mails. Please help me to forward all mails in a saved folder with attachments if any.

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0
    you could add the mail that you want to forward to the attachments.

  6. #6
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Unhappy Forward outlook mails with excel VBA

    Hi,

    Thank you for the reply...but let me expand the question for your better understanding.

    I have copied some mails from outlook inbox to a folder. Some mails are with attachments and some are without. I need to automate it with excel vba to forward those mails to an email ID that i provide in one cell of excel sheet. I need to forward the mails to keep the format and attachments unchanged. Please help me to solve the problem as it's a project I am doing and having problem solving it on time.

    Regards,
    Malay

  7. #7
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    So are you saying that you want to open the saved mails from the hard disk folder, and then just forward those to certain mail IDs?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  8. #8
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0
    If you want to email all files in a folder, to an email address
    (in this case it will be the address in cell A2)

    then this will work

    Code:
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2010
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        Dim StrFile As String
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "See attached" & vbNewLine
    
    
        On Error Resume Next
        With OutMail
            .To = Range("a2").Value      'Email Address (can be a cell reference)
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = strbody
            StrFile = Dir("C:\*")  'location of files to send
            Do While Len(StrFile) > 0
                .Attachments.Add ("C:\" & StrFile) 'insert your file path here too no Asterisk *
                StrFile = Dir
            Loop
            .Display                     'or use .Send
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

    if you want to open the mails and send them i dont think i will be able to help

  9. #9
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Lightbulb Forward outlook mails with excel VBA

    Hi,

    Thank you so much, but sorry to say this solution did not solve my purpose. I need to open each saved ".msg" file and forward it to a certain mail address, reason i want to forward it to keep the mail format and attachment unchanged.

    I can read the mail and then take the body content to another mail and then send it to the recipients with attachments if any but after doing this the format get messed. So can you please help me to format the body of the mail content after i put the body content from the saved mails to the new mail body. I am following your code to send mails. So use the same method but provide me solution to format the body of the mail.

    Thanks...

  10. #10
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0
    Morning Malay

    unfortunately I am not all that informed on this subject, as I only ever needed it to generate new mails. I have never worked with reading them or forwarding them.

    For the record I have just tried to send an email, that has attachments & was saved in a folder, as an attachment. it worked fine with the attachments and formatting.

Similar Threads

  1. Replies: 2
    Last Post: 05-23-2013, 08:08 AM
  2. Replies: 1
    Last Post: 05-22-2013, 01:50 PM
  3. How To Send Outlook Email Using VBA
    By mfaisalrazzak in forum Excel Help
    Replies: 7
    Last Post: 03-03-2013, 03:09 AM
  4. Send Mail Using VBA In Excel And Attach Files
    By macenmin in forum Excel Help
    Replies: 1
    Last Post: 08-03-2012, 01:03 AM
  5. Send Lotus Notes Email Using VBA
    By ramakrishnan in forum Excel Help
    Replies: 1
    Last Post: 09-08-2011, 09:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •