0

I am trying to create a submit button in Excel 2016 using a macro with the below code

Sub Submitbutton14_Click()

Dim x As Outlook.Application
Dim y As Outlook.MailItem
Set x = CreateObject("Outlook.Application")
Set y = oLapp.CreateItem(0)
With y
.Subject = ""
.CC = ""
.To = "[email protected]"
.Body = ""
.Attachments.Add '(path to the attachment,either hard coded or
                    ' variable)
.Display
End With
Set x = Nothing
Set y = Nothing
'
End Sub

When I run the macro I see a Compile Error: Argument not Optional with Sub Submitbutton14_Click() highlighted in yellow. Can you advise what I am doing wrong? I am completely new to VBA and have found this code online and have modified parts of it to fit my need?

Many Thanks

5
  • You need to add an attachment path
    – Nathan_Sav
    Commented Jan 9, 2017 at 9:45
  • When adding the file path I see a Run-time error 424: Object Required. Using the debug option highlights Set y = oLapp.CreateItem(0) in yellow.
    – tom
    Commented Jan 9, 2017 at 9:48
  • 1
    Use x instead of oLapp
    – Rory
    Commented Jan 9, 2017 at 9:51
  • Yes, the MSDN page uses olApp you use x. :)
    – Nathan_Sav
    Commented Jan 9, 2017 at 9:52
  • OK thanks I will give it a try and let you know
    – tom
    Commented Jan 9, 2017 at 10:01

1 Answer 1

0

You need to add an attachment path

https://msdn.microsoft.com/en-us/library/office/ff869553.aspx

Source is required.

Also, you can use new outlook.application, rather than createobject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.