I am working on a project for my department involving a request off log in Excel. I developed a userform so we have standardized responses that are transferred to a different sheet in the workbook, and I've set up the file so that when someone requests off work and saves the file, Outlook opens up and a link to the Excel file gets emailed to the relevant parties.
My boss wants me to add one final thing to this...he wants the last line of data (the most recent request off) to be pasted into the email, so he can get a preview of who requested off.
I've found a lot on finding the last row populated with data...but I'm relatively new to VBA, so I'm having a hard time integrating this request into the existing code. The code for the email is shown below...it is saved to the workbook. If needed, I can post the code for the Userform. This code does work...Outlook does open. I just need to paste the last row from the worksheet (which is the most recent information from the userform) into the email (title or body...does not matter, really). I tried using code that was similar to what was in the userform for transferring data to the spreadsheet (for example: ws.Cells(iRow, 1).Value = Me.LastName.Value) and placing into the code below. It did not really work. Any suggestions would be appreciated, and thanks in advance for the help. I did try the DeBruin website, various internet sources, and searching through the forum here for previous answers to similar questions. Like I said, I'm fairly new to this, so the answer might have went over my head.
Email when file is saved
My boss wants me to add one final thing to this...he wants the last line of data (the most recent request off) to be pasted into the email, so he can get a preview of who requested off.
I've found a lot on finding the last row populated with data...but I'm relatively new to VBA, so I'm having a hard time integrating this request into the existing code. The code for the email is shown below...it is saved to the workbook. If needed, I can post the code for the Userform. This code does work...Outlook does open. I just need to paste the last row from the worksheet (which is the most recent information from the userform) into the email (title or body...does not matter, really). I tried using code that was similar to what was in the userform for transferring data to the spreadsheet (for example: ws.Cells(iRow, 1).Value = Me.LastName.Value) and placing into the code below. It did not really work. Any suggestions would be appreciated, and thanks in advance for the help. I did try the DeBruin website, various internet sources, and searching through the forum here for previous answers to similar questions. Like I said, I'm fairly new to this, so the answer might have went over my head.
Email when file is saved
Code:
[/FONT][/COLOR]Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Outlook As Object, EMail As Object
Dim ws As Worksheet
Set ws = Worksheets("RequestLog")
Set Outlook = CreateObject("Outlook.Application")
Set EMail = Outlook.CreateItem(0)
With EMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Employee Has Requested Off Work: Please See Attached for Updated Request Off Log"
.HTMLBody = _
"
" & _
"
Chr(34) & ">Download Now
"
.Display
End With
Set EMail = Nothing
Set Outlook = Nothing
End Sub