rarchibald
New Member
- Joined
- May 26, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hi there,
I am using the code below to email out a report (using task scheduler & macro launcher to email our daily). The report I'm emailing out contains macro buttons, relating to two modules (Module1 and Module2). The code below works as far as sending the workbook as an attachment, but the modules are not included in the workbook that's sent. I've been looking at this post to try and integrate it in the code below - VBA to Copy a Module to Another Workbook - but am struggling. Any ideas? I need to copy the two modules to the temporary file that is saved and sent.
Thanks in advance for any advice!
-Rob
I am using the code below to email out a report (using task scheduler & macro launcher to email our daily). The report I'm emailing out contains macro buttons, relating to two modules (Module1 and Module2). The code below works as far as sending the workbook as an attachment, but the modules are not included in the workbook that's sent. I've been looking at this post to try and integrate it in the code below - VBA to Copy a Module to Another Workbook - but am struggling. Any ideas? I need to copy the two modules to the temporary file that is saved and sent.
Thanks in advance for any advice!
-Rob
VBA Code:
Option Explicit
Sub EmailandSaveCellValue()
'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String, MailSub As String, MailTxt As String
Dim MailTo As String
Dim MailCC As String
'*********************************************************
'Set email details; Comment out if not required
MailTo = Range("Emails")
MailCC = Range("ccEmails")
'Const MailBCC = "some3@someone.com"
MailSub = "Daily Firmwide Utilization Report"
MailTxt = "Attached is the daily utilization report for " & Range("DailyDate") & ". You can drill down on practice groups, professionals and matters. This report is default to show you the previous business days' time entries. If you select the tab on the bottom you can modify the time period to your desires."
'*********************************************************
'Turns off screen updating
Application.ScreenUpdating = False
'Makes a copy of the active workbook and save it to
'a temporary file
ActiveWorkbook.RefreshAll
ActiveWorkbook.Save
ActiveWorkbook.Sheets.Copy
Set WB = ActiveWorkbook
FileName = "Firmwide Utilization " & Range("DailyDate")
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\Users\rarchibald\Desktop\" & FileName & ".xlsm", FileFormat:=52
'Creates and shows the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = MailTo
.Cc = MailCC
.Bcc = ""
.Subject = MailSub
.Body = MailTxt
.Attachments.Add WB.FullName
.Send
End With
'Deletes the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False
'Restores screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub