Every salesmen is linked to a number (1-20). I change Cell C1 to get a different salesmen. I am using vlookup and advanced filter.
Sub Mail_every_Worksheet()
Dim sh As Worksheet
Application.ScreenUpdating = False
Range("C1").Select
ActiveCell.FormulaR1C1 = "1"
Range("A4").Select
Range("A4:H9").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("B1:B2"), Unique:=False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
sh.Copy
ActiveWorkbook.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & ".xls"
ActiveWorkbook.SendMail ActiveSheet.Range("a1").Value, _
"Subject_line"
ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
ActiveWorkbook.Close False
End If
Next sh
Application.ScreenUpdating = True
Range("C1").Select
ActiveCell.FormulaR1C1 = "2"
Range("A4").Select
Range("A4:H9").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("B1:B2"), Unique:=False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
sh.Copy
ActiveWorkbook.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & ".xls" ActiveWorkbook.SendMail ActiveSheet.Range("a1").Value, _
"Subject_line"
ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
ActiveWorkbook.Close False
End If
Next sh
Application.ScreenUpdating = True
End Sub
I am getting a run-time error "1004"
The file name or path does not exist.
the file is being used by another program.
the workbook you are trying to save has the same name as the currently open workbook.