VBA Coding Error

Willsy3369

New Member
Joined
Aug 3, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Below is a code that I am using to send via email. To use you have to have the Outlook app open. Currently this has been working a treat, but now I'm getting a "Run-time error '5': Invalid procedure call or argument. When I debug "send" in the code is highlighted. Can someone help.

Sub CopyRngToOutlook1()
Dim doc As Object, rng As Range

msg = Range("B14")
Location = Range("E14")

Set rng = Sheets("Locksmith").Range("D3:L33")
With CreateObject("Outlook.Application").CreateItem(0)

Set doc = .GetInspector.WordEditor
rng.CopyPicture
doc.Range(0, 0).Paste
'.To = "ian.wills@justice.vic.gov.au"
'.CC = ""
.Subject = "Lock & Key Fault - MRC - D10"
'.Display
.send

MsgBox "Thank you, an email has been sent to" & vbNewLine & "DJCS-CV-LOCKSMITH SERVICES!", vbInformation
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I get an error on that line because the To assignment is commented out. It is different than the error you get.

If I uncomment the To and Subject assignments, I get the same error as you.

If I also uncomment the .Display line, it is sent successfully (I changed the To address). Consider that a viable workaround.

I don't know why you are getting an error if you do not Display it first.

Also note:

You have undeclared variables. I strongly recommend to everyone that they use Option Explicit and declare variables. Doing so prevents a lot of bugs and runtime errors.

Variable Location is set but not used.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,189
Members
452,616
Latest member
intern444

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