Compile Error: Invalid use of property

Evil Bean Counter

New Member
Joined
Feb 7, 2022
Messages
7
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Replace the Colon with a period (full stop) where shown in BOLD & see if this resolves your issue.

Rich (BB code):
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\David\Excel\" & ActiveSheet.Range("G3").Text

Dave
 
Upvote 0
This is probably a stupid question but where am I looking to see a colon in BOLD?
You placed a colon (shown in bold) where a period should be which may explain the error
Rich (BB code):
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\David\Excel\" & ActiveSheet: Range("G3").Text

Dave
 
Upvote 0
Thanks for the clarification.

That didn't work I'm afraid, its still highlighting the top line as the error.
 
Upvote 0
Curious compiles ok for me - Is it reporting the same error?

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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