Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Compile error: Argument not optional | Excel Programming | |||
Compile Error Argument Not optional | Excel Discussion (Misc queries) | |||
Argument not optional Error 449! Need Help | Excel Programming | |||
Compile Error: Argument not optional | Excel Programming | |||
error message: compile error, argument not optional | Excel Programming |