Run time error

dwarek

Board Regular
Joined
Jul 15, 2016
Messages
77
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
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,773
This (probably) won't help you narrow down the problem, but your code works perfectly on my machine.

You have MS Outlook installed, yes?
 

clares

Well-known Member
Joined
Mar 14, 2002
Messages
557
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
 

Forum statistics

Threads
1,081,546
Messages
5,359,455
Members
400,529
Latest member
Ratish52

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top