Office 365
I cobbled this macro together and it almost works as planned. The macro copies data from a pivot table to a new workbook, saves the new workbook, and emails the original workbook to the designated email address. How can I modify the code to email the new workbook?
I cobbled this macro together and it almost works as planned. The macro copies data from a pivot table to a new workbook, saves the new workbook, and emails the original workbook to the designated email address. How can I modify the code to email the new workbook?
VBA Code:
Sub PVAL()
Application.ScreenUpdating = False
Range("Art").Select
Selection.ShowDetail = True
ActiveSheet.Name = "AG"
Selection.Copy
Workbooks.Add
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Columns.AutoFit
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A1"), Order:=xlAscending 'Date
.SetRange ActiveSheet.UsedRange
.Header = xlYes
.Apply
End With
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Users\b144519\Documents\Art " & Format(DateAdd("d", -1, Date), "mmddYY") & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Range("A1").Select
Dim emailapp As Outlook.Application
Set emailapp = New Outlook.Application
Dim emailitem As Outlook.MailItem
Set emailitem = emailapp.CreateItem(olMailItem)
emailitem.To = "Art@YYYY.com"
emailite.CC = "Steven@xxx.com"
emailitem.Subject = "AutoPay Update"
emailitem.HTMLBody = "Here is the updated file, updated through yesterday."
Source = ThisWorkbook.FullName
emailitem.Attachments.Add Source
emailitem.Send
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Last edited: