+ Reply to Thread
Results 1 to 7 of 7

Multiple e-mailing

Hybrid View

Fairport Multiple e-mailing 06-17-2009, 07:34 AM
Greg M Re: Multiple e-mailing 06-17-2009, 10:05 AM
Fairport Re: Multiple e-mailing 06-17-2009, 12:51 PM
Greg M Re: Multiple e-mailing 06-17-2009, 04:06 PM
Fairport Re: Multiple e-mailing 06-18-2009, 05:22 PM
Charlize Re: Multiple e-mailing 06-19-2009, 07:28 AM
Fairport Re: Multiple e-mailing 07-02-2009, 07:14 AM
  1. #1
    Registered User
    Join Date
    04-22-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Thumbs up Multiple e-mailing

    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
    Attached Files Attached Files
    Last edited by Fairport; 07-02-2009 at 07:15 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Multiple e-mailing

    Hi there,

    I've read your post very quickly so this is just a knee-jerk reaction which might or might not be useful.

    First point:

        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
    Doesn't this code deliver the same result regardless of the Excel version in use?

    Second point:
    Why not always save your file in Excel 2003 format? That way your sales team won't need to use the MS Office Compatability file, but machines running Excel 2007 will be able to open the Excel 2003 files.

    Third point:
    One way of overcoming the "Enable/Disable Macros" prompt is to digitally sign your workbook and instruct your users to check the "Always trust projects from this source" box when it appears. From what I can tell from your code, this would mean digitally signing your Workbook Template "xlWBATWorksheet".

    As I said at the start, this is just an initial reaction, but I hope it might be of some assistance to you.

    Please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    04-22-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Multiple e-mailing

    Thanks for your reply.
    To answer your first point, the original code
    If Val(Application.Version) < 12 Then
            'You use Excel 2000-2003
            FileExtStr = ".xlsx": FileFormatNum = 51
        Else
            'You use Excel 2007
            FileExtStr = ".xls": FileFormatNum = -4143
        End If
    looked at what version of Office is running, in my case 2007 so it saved the file as ".xlsx", which is not the version the sales team is running with. I changed the code to
    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
    to force it to save to 2003 regardless. I'm sure there is a another way to code this but with my limited knowledge I experimented and this worked.

    Your second point is what I achieved above, but that gave me another problem because when it saves the file it comes up with the compatability check box which is one of my inquiries as how to avoid or disable the box that appears.

    On the third point it not disabling/enabling macros that I'm looking at. When (after allowing a save in 2003 point 2 above) it then asks you if you want to send an e-mail, press "allow" to send, "Deny" to cancel and "Help". It is this box I want to avoid or disable.

    What I would like to achieve is the operator to click button 1 and all the reports are e-mailed to all the sales managers with no further input from them.

    Thanks again for you help.
    Fairport

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Multiple e-mailing

    Hi again,

    Thanks for your feedback, and sorry for the total lack of help from this side.

    Almost all of the work I do uses Excel 2000, so that's why I'm less familiar with aspects like compatability checks etc.

    The more I see of the "improvements" in the latest Office suites, the more I'm convinced that if something isn't broken, it shouldn't be fixed.

    Sorry once again,

    Greg M

  5. #5
    Registered User
    Join Date
    04-22-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Multiple e-mailing

    Thanks Greg M for trying.

  6. #6
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245

    Re: Multiple e-mailing

    For the looping through the salesmen. Maybe the displayalerts will hide the unwanted messagebox. Not sure cause I can't test it now.
    Sub Mail_Range()
    Dim mysalespeople
    Sheets("Table").Select
    Range("A2").Select
    'Andy, Fairport, Charlize are the names of your salespeople
    For Each mysalespeople In Array("Andy", "Fairport", "Charlize")
        ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
        ActiveWindow.ScrollColumn = 1
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Salesman").ClearAllFilters
    'Loop through all your salespeople
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Salesman").CurrentPage = _
            mysalespeople
        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
    'Not sure if this would help to hide the messagebox
    'concerning the saving.
        Application.DisplayAlerts = False
        With Dest
            .SaveAs TempFilePath & TempFileName & FileExtStr, _
                    FileFormat:=FileFormatNum
            On Error Resume Next
        Application.DisplayAlerts = True
    'If the mailaddress before @ is the same as the name of mysalespeople,
    'your in luck, otherwise you'll have to use andy$andy@abcdefg.com
    'ie array("andy$andy@abcdefg.com","fairport$fairport@abcdefg.com")
    'then with split(mysalespeople,"$")(0) you've got the name
    'and with  split(mysalespeople,"$")(1) you've got the mailaddress
            .SendMail mysalespeople & "@abcdefgh.com", _
                      "Trial select cell email to " & mysalespeople
            On Error GoTo 0
            .Close SaveChanges:=False
        End With
        Kill TempFilePath & TempFileName & FileExtStr
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    'next name
    Next mysalespeople
    End Sub
    Charlize
    Last edited by Charlize; 06-19-2009 at 07:30 AM.

  7. #7
    Registered User
    Join Date
    04-22-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Multiple e-mailing

    Thank you Charlize, that seems to have done the trick after tweeking here and there to fit the spreadsheet it works a treat.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1