• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with macro to send email with current worksheet data

Bricklin

New Member
I have a workbook that I use to create and save quotes. I would like to add an email macro that 1st saves the quote as the name that is created in the working macro below and then opens outlook and creates an email with the .pdf (as named below) attached.

Additionally, I woulds like to add in the body of the email a couple values such as... "Please see the attached quote for (text in cell A2)".

"The total price is (value in cell w2)".

Any help would be greatly appreciated.

THANKS!


Code:
Sub Save_Float()
If Dir("C:\Quotes Folder\", vbDirectory) = vbNullString Then MkDir "C:\Quotes Folder"
If Dir("C:\Quotes Folder\" & [Input!F12] & "\", vbDirectory) = vbNullString Then MkDir "C:\Quotes Folder\" & [Input!F12] & "\"
Call Flash_Float_Quote
ThisFile = "C:\Quotes Folder\" & [Input!F12] & "\" & Range("Magic!P17").Value & Range("Magic!P10").Value & Format(Range("Input!R4").Value, "mm-dd-yyyy")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=ThisFile
End Sub
 
Last edited by a moderator:
Check it..

Code:
Sub Save_Float_email()
If Dir("C:\Quotes Folder\", vbDirectory) = vbNullString Then MkDir "C:\Quotes Folder"
If Dir("C:\Quotes Folder\" & [Input!F12] & "\", vbDirectory) = vbNullString Then MkDir "C:\Quotes Folder\" & [Input!F12] & "\"
Call Flash_Float_Quote
ThisFile = "C:\Quotes Folder\" & [Input!F12] & "\" & Range("Magic!P17").Value & Range("Magic!P10").Value & Format(Range("Input!R4").Value, "mm-dd-yyyy")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisFile

    With CreateObject("Outlook.Application").CreateItem(0)
        .To = ""
        .CC = ""
      ' .BCC = ""
        .Subject = ""
'        .BodyFormat = .olFormatHTML
        .HTMLBody = "Please see the attached quote for " & [Input!A2] & ".<br><br>The total price is " & [Input!W2] & "."
        .Attachments.Add ThisFile
        .Display
        '.Send
    End With

End Sub
 
File saves correctly in the quotes folder as before but getting an error while executing the email part..... Message window says "Cannot find this file. Verify the path and file name are correct."

Debug of code highlights this line

.Attachments.Add ThisFile
 
Last edited:
One more issue... One of the fields I'd like to include in the email is currency . How do I format that field?

It is currently [Input!W2]
 
Check it...

Code:
.HTMLBody = "Please see the attached quote for " & [Input!A2] & ".<br><br>The total price is " & Format([Input!W2], "Currency") & "."
 
Back
Top