Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mailing with Excell vbscript help

Status
Not open for further replies.

fotelefth

Technical User
Feb 24, 2012
2
GR
Hi im new to vbScript.
I have an Excel sheet, one column with emails and another with Subjects (for the emails). Im trying to send emails to the different recipients with different subjects e.g.:

A B
1 mail1@mail.com subject1
2 mail2@mail.com subject2
3 mail3@mail.com subject3

I have the following code:

Sub email()

Dim Count As Integer

Set objMessage = CreateObject("Outlook.Application").OutApp.CreateItem(0)
For Count = 1 To 3 //Assuming there are only 3 rows. But how can i make it loop till the end of the rows?
objMessage.Subject = "Mail to" & ActiveSheet.Cells(Count, 1) //e.g. Email to mail1@mail.com must have a subject "Mail to subject1"
objMessage.From = "me@my.com"
objMessage.BCC = ActiveSheet.Cells(Count, 2)//Bcc is required
objMessage.TextBody = "This is some sample message text."
objMessage.Send
Next

Set objMessage = Nothing

End Sub


I got to many error messages, the latest is:
"Object doesn't support this property or method" at "CreateObject("Outlook.Application").OutApp.CreateItem(0)" Line

Any help with this code?
 
First, this is VBA, not VBScript.
What about this ?
Code:
Set OutApp = CreateObject("Outlook.Application")
For Count = 1 To 3
  Set objMessage = OutApp.CreateItem(0)
  objMessage.Subject = "Mail to" & ActiveSheet.Cells(Count, 1)
  objMessage.To = ActiveSheet.Cells(Count, 2)
  objMessage.Body = "This is some sample message text."
  objMessage.Send
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hmmm seems better now, except i'm getting an "Outlook does not recognize one or more names" error.

Thanks for the help and fast response ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top