send email from excel

przemek

New Member
Joined
Jan 6, 2015
Messages
13
hi

this code used to work in the past (open email form drive, filled send to and displayed email ), probably with older version of outlook, excel. now this code exits form sub at myRecipients.Add ws_names.Cells(i, 1)

thanks for any suggestions


VBA Code:
    Dim ws_names As Worksheet
    Dim i, lr As Integer
    Dim OutApp As Object
    Dim OutMail As Object
    Dim myRecipients, myCCs, myRecipient As Object
    

' setup
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate("C:\Analytics\Out_notes\ATP_send.oft") ' [B][U]<= seems that OutMail = "" leading to issues later[/U][/B]
    Set myRecipients = OutMail.Recipients
    Set myCCs = OutMail.Recipients
    Set ws_names = ThisWorkbook.Sheets(1)
    
       
 'add recipients
    
    lr = ws_names.Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To lr
        myRecipients.Add ws_names.Cells(i, 1)   ' [B][U]<= at this point program exits sub[/U][/B]
    Next
    If Not myRecipients.ResolveAll Then
        For Each myRecipient In myRecipients
            If Not myRecipient.Resolved Then
                MsgBox myRecipient.Name
            End If
        Next
    End If
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
not completed this yet - but seems that some library needs to be added first

To use early binding, you first need to reference the available Outlook object library. To do this from Visual Basic (VB) or Visual Basic for Applications, follow these steps:

  1. In the Visual Basic Editor, on the Tools menu, click References.
  2. Click to select the Microsoft Outlook 15.0 Object Library check box, and then click OK.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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