VBA excel code to send attachment email RRS feed

  • Question

  • Hi,

    i have a Excel database with quotes for a friends computer store and i am trying to some how add a button to it so that when i press the button it asks for the users email that the excel file can be sent to as a attachment and have the subject as Quote for PC BUILD REQUEST .

    using outlook. How can i do this? i tryed getting it to run but was getting a heap of errors so thought i would start from scratch and ask some one for some help  

    Sunday, June 17, 2012 9:16 AM

All replies

  • Try something like this (though you are short on details):

    Sub SendOutlookQuote()
        Dim objOutlook As Object
        Dim eMailMsg As Object
        Dim r As Long
        Set objOutlook = CreateObject("Outlook.Application")
        Set eMailMsg = objOutlook.CreateItem(objOutlookMailItem)
        'all the data to be send is on the current row of the database
        r = ActiveCell.Row
        With eMailMsg
            .To = InputBox("What is the email address?")
            'You could also read the address from a cell like this:
            '.To = ActiveSheet.Cells(r, 1).Value

            .Subject = "Quote for PC BUILD REQUEST"
            .Body = ActiveSheet.Cells(r, 2).Value & vbCrLf & _
                ActiveSheet.Cells(r, 3).Value & vbCrLf & _
                ActiveSheet.Cells(r, 4).Value & vbCrLf & _
                ActiveSheet.Cells(r, 5).Value & vbCrLf & _
        End With
        Set objOutlook = Nothing

    End Sub

    HTH, Bernie

    Sunday, June 17, 2012 1:18 PM