Reputation: 11
I need to get email address based on employee id.
I copy the employee ids from Excel and paste them in the "To" field of Outlook mail.
I am unable to click ctrl + K
using the macro code.
I use the below code to paste the employee ids in Outlook application.
Sub Combinedata()
Dim i As Integer
Dim count As Integer
Dim s As String
Dim outRec As Object
count = Cells(Rows.count, "A").End(xlUp).Row
For i = 1 To count
s = s & Cells(i, 1) & ";"
Next
'Range("D2") = s
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo 0
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = s
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End Sub
Upvotes: 1
Views: 542
Reputation: 9179
.Recipients.ResolveAll
replicates ctrl + K.
Option Explicit ' Consider this mandatory
' Tools | Options | Editor tab
' Require Variable Declaration
'
' If desperate declare as variant
Sub Combinedata()
Dim i As Long
Dim count As Long
Dim s As String
Dim OutApp As Object
Dim outMail As Object
count = Cells(Rows.count, "A").End(xlUp).Row
For i = 1 To count
s = s & Cells(i, 1) & ";"
Next
Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)
With outMail
.To = s
.Recipients.ResolveAll
.Display
End With
End Sub
Upvotes: 1