I have code that allow me to attach a particular sheet from one workbook to outlook
The code works perfectly. However, I have several workbooks that have the same sheet name "Fixed assets Recon" that needs to be attached
I am usure how to amend the code so that the same sheet name can be attached from mseveral workbooks
It would be appreciated if someone could kindly assist
Sub SendFiles()
Application.DisplayAlerts = False
Dim lCount As Long
Dim vFilenames As Variant
Dim sPath As String
Dim lFilecount As Long
Dim sFullName As String
sPath = "C:\Fixed assets\"
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)
Sheets("Fixed assets Recon").Copy
ActiveWorkbook.SaveAs Replace(vFilenames(lCount), "*.xls", ".xls") & ".xls", FileFormat:=xlExcel8
vFilenames(lCount) = ActiveWorkbook.FullName
For Each sht In Sheets(Array("Fixed assets Recon"))
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 "[email protected]", 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 = "Movement accounts"
.body = .body & "Hi Carl"
.body = "Attached please find Fixed Asset Recons as at " & Format(Month(Date) - 1 & " " & Year(Date), "mmmm yyyy") & vbNewLine & vbNewLine
.body = .body & "Regards" & vbNewLine & vbNewLine
.body = .body & "Howard"
For lCt = LBound(vFiles) To UBound(vFiles)
.attachments.Add CStr(vFiles(lCt))
Next
.Display
Set oOLapp = Nothing
Set oMailItem = Nothing
End With
End Sub
Display More
I posted on Mr Excel.com yesterday
http://www.mrexcel.com/forum/e…-mseveral-wqorkbooks.html