LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Problem auto generating e-mail to several recipients - argument not optional error message

Hello,

In a work sheet, I have a list of e-mail addresses. I am trying to
write the code for a button that sends an e-mail, with all the
addresses in the list as recipients. What the code basically does is
that a for statement runs through the list and adds the recipients via
the Set objRecipient command. I keep getting the "argument not
optional" error message, pointing to the row with the Set objRecipient
command. The only code I've written myself is the for statement, the
rest is ripped off this forum. Could anyone of you VBA gurus have a
look through the code and give me some suggestions as to how to fix
it. The for statement itself is probably not excellently written, so
if you have any input on how to improve it or make it neater, please
share.

Is it possible to send a hyperlink to the workbook (or even better to
a specific worksheet in the workbbok) in the body of the e-mail? The
application will be posted on a company intranet, so the link should
work.

Thanks alot
Nils

Private Sub CommandButton2_Click()
Dim objOutlook As Object
Dim objMailItem As Object
Dim objRecipient As Object
Dim objNameSpace As Object
Dim i As Integer
Dim cell As Range


Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
objNameSpace.Logon , , True


Set objMailItem = objOutlook.CreateItem(0)

For i = 8 To 19 ' The e-mail
list is in the range D8-D19

Set cell = Range("D" & i)
cell.Select

If IsEmpty(ActiveCell) Then ' Checks if the
cell is empty
GoTo nextLine
End If

Set objRecipient = objMailItem.Recipients.Add.cell.Value '
This is where I get "Argument not optional"
objRecipient.Type = 1

nextLine:

Next i

objMailItem.Subject = "Subject"
objMailItem.Body = "Body" ' Is it possible to
attach a link to this workbook here?
objMailItem.Send

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error: Argument not optional ilia Excel Programming 0 December 13th 06 02:57 PM
Compile Error Argument Not optional [email protected] Excel Discussion (Misc queries) 1 August 16th 06 04:58 PM
Argument not optional Error 449! Need Help bad_boyu Excel Programming 3 July 26th 06 12:52 PM
Compile Error: Argument not optional Brett Smith[_2_] Excel Programming 1 January 19th 06 05:39 PM
error message: compile error, argument not optional Pierre via OfficeKB.com Excel Programming 3 September 5th 05 03:45 PM


All times are GMT +1. The time now is 01:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"