A report needs to be distributed to area sales managers every month by e-mail.
I have found code (courtesy of Ron de Bruin http://www.rondebruin.nl/mail/folder1/mail4.htm) that will select the data that needs to be sent, and modified it to suit my spreadsheet.
Sub Mail_Range()
Sheets("Table").Select
Range("A2").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveWindow.ScrollColumn = 1
ActiveSheet.PivotTables("PivotTable1").PivotFields("Salesman").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Salesman").CurrentPage = _
"Andy"
Range("K2").Select
'Working in 2000-2007
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Set Source = Nothing
On Error Resume Next
Set Source = Range("K5:s500").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, " & _
"please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = "Selection of " & wb.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xls": FileFormatNum = -4143
End If
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
'please insert a valid email address if you need to test this code
.SendMail "project@abcdefgh.com", _
"Trial select cell email to ANDY"
On Error GoTo 0
.Close SaveChanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
'Options for all Excel versions :
'Save the one sheet workbook to csv, txt or prn.
'FileExtStr = ".csv": FileFormatNum = 6
'FileExtStr = ".txt": FileFormatNum = -4158
'FileExtStr = ".prn": FileFormatNum = 36
'Options only for Excel 2007 :
'This are the main formats in Excel 2007 :
'51 = xlOpenXMLWorkbook (without macro's in 2007, xlsx)
'52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007, xlsm)
'50 = xlExcel12 (Excel Binary Workbook in 2007 with or without macro’s, xlsb)
'56 = xlExcel8 (97-2003 format in Excel 2007, xls)
'FileExtStr = ".xlsb": FileFormatNum = 50
'FileExtStr = ".xlsx": FileFormatNum = 51
'FileExtStr = ".xlsm": FileFormatNum = 52
'FileExtStr = ".xls": FileFormatNum = 56
End With
End Sub
1. Is there a way to loop the code and send e-mails to each sales manager?
2. As the sales team operate Office 2003 on their laptops as opposed to our 2007 is there a way to avoid the compatibility check every time we send an e-mail and also is there a way to avoid the “allow-deny” box too?
I have already suggested that they download MS compatability file, but 1 sales guy has 'downed his laptop' so want to try and avoid a similar event with the others.
Thanks in advance
Bookmarks