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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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
when you are testing, has outlook been started
 
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,214,523
Messages
6,120,039
Members
448,940
Latest member
mdusw

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