Emailing an invoice from Excel

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I have an invoice in my workbook which my code saves as a pdf document and then emails it as an attachment.

My problem is I have the directory of the pdf hard coded into my code so when I give this workbook to someone else it does not work on their computer
I currently save the invoice in the same directory as the workbook with the same name as the workbook and then send the mail and thereafter for each other invoice I just overwrite the pdf with the next invoice and email each in turn (Much of this code was provided by Mr Excel)
VBA Code:
Dim emailApplication As Object
Dim emailItem As Object

Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)

' save the file as pdf
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\User\Documents\Clay\2021 SA Grand\Entries.pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
    Sheets("Receipt").Select

If Range("Receipt!L37").Value = "" Then
    MsgBox (Range("Receipt!C46").Value & " " & "has no e-mail address")
    Exit Sub
End If
' Now we build the email.
emailItem.to = Range("Receipt!L37").Value

emailItem.Subject = "SA Grand 2021 Entry and Invoice"

emailItem.Body = "Thank you for your entry in the SA Grand 2021 at ,y club" & vbCr & vbCr & "Please check that you have been entered correctly for this event." & vbCr & vbCr & "Your squad details, time and range will be added the Sunday before the competition and sent to you." & vbCr & vbCr & "The invoice for the entry is on the bottom of the attachment." & vbCr & vbCr & "Regards" & vbCr & " My name" & vbCr & "My number"

'   Attach current Workbook
'    emailItem.Attachments.Add ActiveWorkbook.FullName

' Attach any file from your computer.
emailItem.Attachments.Add ("C:\Users\User\Documents\Clay\2021 SA Grand\Entries.pdf")

' Send the Email
emailItem.Send

Set emailItem = Nothing
Set emailApplication = Nothing

End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top