+ Reply to Thread
Results 1 to 2 of 2

VBA EMail

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    23

    VBA EMail

    Hi,

    Hope everyone is well.

    How do i edit the below code that automatically sends an email the the specified address, i need to change it so that it allows me to write a message in the message body of the e-mail and then i will click send on the email manually?

    Sub Mail_Range()
    Application.Run "'Recall_Tracker-MPS.xlsm'!Unprotect"
        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
        
    'insertion
        CurCol = Selection.Interior.ColorIndex
        Selection.Interior.ColorIndex = 6
    'end of insertion
    
        Set Source = Nothing
        On Error Resume Next
        Set Source = Range("A1:U36").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
        
    'insertion
        wb.Activate
        Selection.Interior.ColorIndex = CurCol
    'end of insertion
        
        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 = ".xlsx": FileFormatNum = 51
        End If
    
        With Dest
           .SaveAs TempFilePath & TempFileName & FileExtStr, _
                    FileFormat:=FileFormatNum
            On Error Resume Next
            .SendMail "email address here", _
                      "subject line here"
            On Error GoTo 0
            .Close SaveChanges:=False
        End With
    
        Kill TempFilePath & TempFileName & FileExtStr
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    ' colourchange Macro
    '
    
    '
        Range( _
            "B6:G22,G23:I23,L23:N23,Q23:S23,P6:Q22,K6:L22,E27:F29,E31:F31,E33:F33,C27:C28") _
            .Select
        Range("C27").Activate
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorLight2
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With
        Range("H6:J22,M6:O22,R6:T22,C26").Select
        Range("C26").Activate
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent5
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With
        Application.Run "'Recall_Tracker-MPS.xlsm'!Protect"
        Range("B2:D2").Select
    End Sub
    Basically i would like it to do all of the above but stop right at the point of sending so that i can write a message and then click send?

    Regards,
    Jamie

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: VBA EMail

    I'm not sure that is possible using SendMail.

    You will more than likely need to use Outlook and then display the message rather than just sending it.

    There are some very good code examples here: http://www.rondebruin.nl/sendmail.htm

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

+ 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