Run time error

dwarek

Board Regular
Joined
Jul 15, 2016
Messages
79
hello i have developed code but it shows a run time error can some one please advise whats is the issue
Private Sub CommandButton1_Click()
Range("A2").Select
While Not ActiveCell = ""
Mail_To = ActiveCell.Offset(0, 0)
Mail_Subject = "testing"
Mail_Voting = ActiveCell.Offset(0, 4)
Set myolapp = CreateObject("Outlook.Application")
Set myitem = myolapp.CreateItem(olMailItem) ---> error in this line "Method 'Subject' of object'_Mailitem' failed
With myitem


.VotingOptions = Mail_Voting
.To = Mail_To

.Subject = ActiveCell.Offset(0, 1)
.Body = ActiveCell.Offset(0, 2)
.display
End With

ActiveCell.Offset(1, 0).Select
Wend
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This (probably) won't help you narrow down the problem, but your code works perfectly on my machine.

You have MS Outlook installed, yes?
 
Upvote 0
Hi Mole999

I don't know if this will help you but this is what I use and it works using Excel and Outllok 2016

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "xx@xx.xx.xx"
.CC = ""
.BCC = ""
.Subject = "subject line"
.Body = "Text in the body of the email."
.Attachments.Add ("C:\location of attachment.xlsx")
.Send
End With
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

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