Evil Bean Counter
New Member
- Joined
- Feb 7, 2022
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
I'm working on a a macro that once its working I can take to work at apply to a file there. I've already got a macro that takes an Excel file and saves it as a PDF, but I've been asked if I can arrange for that PDF file to then be emailed to the person who's completed the form.
There will be multiple files, each has a unique name but the file path is consistent.
The file name is present in the active sheet
The recipients email is present in the active sheet
I've put the following together (after watching a YouTube tutorial) but when I run it the top line is flagged as an error Compile Error: Invalid Use of Property but I have no idea what this means or how to solve it. I've tried changing the text but no luck so I'm guessing its something with rest of the text it doesn't like. Can anyone see why this doesn't work?
Sub SendEmail()
ChDir "filepath"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\David\Excel\" & ActiveSheet: Range("G3").Text
Dim OutLookApp As Object
Dim OutlookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("Outlook.application")
Set OutLook.MailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutlookMailItem.Attachments
Recipient = ActiveSheet(E5)
With OutlookMailItem
.To = "Recipient"
.Subject = "PO"
.Body = "The PO form for approval is attached"
myAttachments.Add "C:\Users\David\Excel\" & ActiveSheet: Range("G3").Text ""
.Send
End Sub
There will be multiple files, each has a unique name but the file path is consistent.
The file name is present in the active sheet
The recipients email is present in the active sheet
I've put the following together (after watching a YouTube tutorial) but when I run it the top line is flagged as an error Compile Error: Invalid Use of Property but I have no idea what this means or how to solve it. I've tried changing the text but no luck so I'm guessing its something with rest of the text it doesn't like. Can anyone see why this doesn't work?
Sub SendEmail()
ChDir "filepath"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\David\Excel\" & ActiveSheet: Range("G3").Text
Dim OutLookApp As Object
Dim OutlookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("Outlook.application")
Set OutLook.MailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutlookMailItem.Attachments
Recipient = ActiveSheet(E5)
With OutlookMailItem
.To = "Recipient"
.Subject = "PO"
.Body = "The PO form for approval is attached"
myAttachments.Add "C:\Users\David\Excel\" & ActiveSheet: Range("G3").Text ""
.Send
End Sub