amanphilip
New Member
- Joined
- Jul 4, 2023
- Messages
- 18
- Office Version
- 365
- 2019
- Platform
- Windows
Hello and Good Day!
I am currently new to VBA and currently trying to create a macro wherein it will capture the Date the email was sent in outlook and place it somewhere in the workbook template. Here's the current code in the workbook:
I found this code online however this code is for outlook VBA and I am trying to figure out how can I insert this code with the above(VBA EXCEL)
Any help is appreciated. Thank you!
I am currently new to VBA and currently trying to create a macro wherein it will capture the Date the email was sent in outlook and place it somewhere in the workbook template. Here's the current code in the workbook:
VBA Code:
Sub bankwide()
Dim OutApp As Object
Dim OutMail As Object
Dim recipient As String
Dim rng As Range
Dim lstrow As Long
Dim IDno, lname, fname, fname2, mname, sector, group, division, department, section, rank, position, OnboardD As String
Dim path, subj2, cc, hiringmanager As String
path = Application.ActiveWorkbook.path
'On Error Resume Next
lstrow = Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Range("C4:C" & lstrow)
For Each cell In rng
IDno = Range(cell.Address).Offset(0, 0).Value
lname = Range(cell.Address).Offset(0, 1).Value
fname = Range(cell.Address).Offset(0, -2).Value
fname2 = Range(cell.Address).Offset(0, 2).Value
mname = Range(cell.Address).Offset(0, 3).Value
sector = Range(cell.Address).Offset(0, 4).Value
group = Range(cell.Address).Offset(0, 5).Value
division = Range(cell.Address).Offset(0, 6).Value
department = Range(cell.Address).Offset(0, 7).Value
section = Range(cell.Address).Offset(0, 8).Value
rank = Range(cell.Address).Offset(0, 9).Value
position = Range(cell.Address).Offset(0, 10).Value
OnboardD = Range(cell.Address).Offset(0, -1).Value
cc = Range(cell.Address).Offset(0, 13).Value
hiringmanager = Range(cell.Address).Offset(0, 12).Value
Set OutApp = CreateObject("Outlook.Application")
'Set OutMail = OutApp.createitemfromtemplate("C:\Users\t-amachavezjr\Desktop\Reports Automation\Resource Team\Email Sending Template\Bankwide_Onboarding.oft")
Set OutMail = OutApp.createitemfromtemplate(path & "\Bankwide_Onboarding.oft")
With OutMail
.to = hiringmanager
.cc = cc
' .BCC = ""
.Subject = "[Action Required] Bankwide Onboarding - Group " & group & " for " & OnboardD
.HTMLbody = Replace(.HTMLbody, "fname", "<b>" & fname & "</b>")
.HTMLbody = Replace(.HTMLbody, "inum", "<b>" & IDno & "</b>")
.HTMLbody = Replace(.HTMLbody, "lname", "<b>" & lname & "</b>")
.HTMLbody = Replace(.HTMLbody, "finame", "<b>" & fname2 & "</b>")
.HTMLbody = Replace(.HTMLbody, "mname", "<b>" & mname & "</b>")
.HTMLbody = Replace(.HTMLbody, "%sec%", "<b>" & sector & "</b>")
.HTMLbody = Replace(.HTMLbody, "%Gr%", "<b>" & group & "</b>")
.HTMLbody = Replace(.HTMLbody, "%Dv1%", "<b>" & division & "</b>")
.HTMLbody = Replace(.HTMLbody, "%Dept%", "<b>" & department & "</b>")
.HTMLbody = Replace(.HTMLbody, "%Sect%", "<b>" & section & "</b>")
.HTMLbody = Replace(.HTMLbody, "%r1%", "<b>" & rank & "</b>")
.HTMLbody = Replace(.HTMLbody, "%Pos%", "<b>" & position & "</b>")
.HTMLbody = Replace(.HTMLbody, "%d1%", "<b>" & OnboardD & "</b>")
.Display
End With
subj2 = OutMail.Subject
Next cell
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I found this code online however this code is for outlook VBA and I am trying to figure out how can I insert this code with the above(VBA EXCEL)
VBA Code:
Sub GetMailProps()
Dim myMail As Outlook.MailItem
For Each myMail In Application.ActiveExplorer.Selection
MsgBox "Mail was sent on: " & myMail.SentOn & vbCr & _
"by: " & myMail.SenderName & vbCr & _
"message was received at: " & myMail.ReceivedTime
Next
Set myMail = Nothing
End Sub
Any help is appreciated. Thank you!
Last edited by a moderator: