I have names of various workbooks in Col A and the email address to cc on col B pertaining to the file name
I have the following code below to email and allow a user to attach a file
Based on the name file attached, I would like the code to look up the email address to cc in Col B based on the file name
It would be appreciated if someone could amend my code to accommodate this
I have the following code below to email and allow a user to attach a file
Based on the name file attached, I would like the code to look up the email address to cc in Col B based on the file name
Code:
.Subject = Application.ActiveWorkbook.Name & " -Summary Sales Report"
It would be appreciated if someone could amend my code to accommodate this
Code:
Sub SendFiles()
Dim lCount As Long
Dim vFilenames As Variant
Dim sPath As String
Dim lFilecount As Long
Dim sFullName As String
sPath = "C:\Summary Sales Reports\"
ChDrive sPath
ChDir sPath
vFilenames = Application.GetOpenFilename("Microsoft Excel files (*.xls),*.xls", , "Please select the file(s) to open", , True)
If TypeName(vFilenames) = "Boolean" Then Exit Sub
For lCount = LBound(vFilenames) To UBound(vFilenames)
Workbooks.Open vFilenames(lCount), UpdateLinks:=False
Application.DisplayAlerts = False
Application.CutCopyMode = False
Sheets(Array("summary")).Copy
ActiveWorkbook.SaveAs Replace(vFilenames(lCount), ".xls", "") & ".summary.xls", FileFormat:=xlNormal
vFilenames(lCount) = ActiveWorkbook.FullName
Application.ScreenUpdating = False
For Each sht In Sheets(Array("summary"))
Sheets(sht.Name).UsedRange.Copy
Sheets(sht.Name).Range("a1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next
Application.ScreenUpdating = True
ActiveWorkbook.Close True
Application.DisplayAlerts = True
Application.CutCopyMode = True
Next
Mailfiles "dave.preswick@xway.com", vFilenames
For lCount = LBound(vFilenames) To UBound(vFilenames)
Kill vFilenames(lCount)
Next
ActiveWorkbook.Close False
End Sub
Sub Mailfiles(sMailAddress As String, vFiles As Variant)
Dim oMailItem As Object
Dim oOLapp As Object
Dim lCt As Long
Set oOLapp = CreateObject("Outlook.application")
Set oMailItem = oOLapp.CreateItem(0)
With oMailItem
.To = sMailAddress
.Subject = Application.ActiveWorkbook.Name & " -Summary Sales Report"
.body = "Attached please find summary sales per region as at " & Format(Application.EoMonth(Date, -1), "mmm yyyy") & " vs the Prior Year" & vbNewLine & vbNewLine
.body = .body & "Regards" & vbNewLine & vbNewLine
.body = .body & "Simon"
For lCt = LBound(vFiles) To UBound(vFiles)
.attachments.Add CStr(vFiles(lCt))
Next
.Display
Set oOLapp = Nothing
Set oMailItem = Nothing
End With
End Sub