stephen li
New Member
- Outlook version
- Outlook 2016 64 bit
- Email Account
- Exchange Server 2013
I try to make a Marco to help our HR to send birthday mail to our colleagues automatically by recording there information into an excel file.
The Marco as below:
-------------------------------------------------------------------------------------------------------------------------------
Sub fa()
On Error Resume Next
Dim rowCount, endRowNo, today
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem
endRowNo = Cells(1, 1).CurrentRegion.Rows.Count
today = Mid(Cells(2, 7).Value, 1, 4)
Set objOutlook = New Outlook.Application
For rowCount = 2 To endRowNo
If today = Mid(Cells(rowCount, 6).Value, 1, 4) Then
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.To = Cells(rowCount, 1).Value
.Subject = Cells(rowCount, 2).Value
.HTMLBody = (Cells(rowCount, 3).Value & Cells(rowCount, 4).Value)
.Send
End With
Set objMail = Nothing
End If
Next
Set objOutlook = Nothing
End Sub
-------------------------------------------------------------------------------------------------------------------------------
My question is for the below Marco, the mail will be sent by the outlook account which the system account.
How can I change the sender to other outlook account by setting the account name and password?
The Marco as below:
-------------------------------------------------------------------------------------------------------------------------------
Sub fa()
On Error Resume Next
Dim rowCount, endRowNo, today
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem
endRowNo = Cells(1, 1).CurrentRegion.Rows.Count
today = Mid(Cells(2, 7).Value, 1, 4)
Set objOutlook = New Outlook.Application
For rowCount = 2 To endRowNo
If today = Mid(Cells(rowCount, 6).Value, 1, 4) Then
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.To = Cells(rowCount, 1).Value
.Subject = Cells(rowCount, 2).Value
.HTMLBody = (Cells(rowCount, 3).Value & Cells(rowCount, 4).Value)
.Send
End With
Set objMail = Nothing
End If
Next
Set objOutlook = Nothing
End Sub
-------------------------------------------------------------------------------------------------------------------------------
My question is for the below Marco, the mail will be sent by the outlook account which the system account.
How can I change the sender to other outlook account by setting the account name and password?