+ Reply to Thread
Results 1 to 2 of 2

Need Help Combing to working VBA codes

Hybrid View

  1. #1
    Registered User
    Join Date
    04-19-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    48

    Need Help Combing to working VBA codes

    Hi all... I might be being a little dumb here, but I have the following codes that work fine, one for an error message when a certain criteria isn't met, the other sends an email template, populated with certain cell values. I woudl like to combine the two, but am struggling (I'm still a relative novice with VBA so the answer is probably simple).

    Private Sub Worksheet_Calculate()
    
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
    
    If Range("F2").Value > " " Then
        strPrompt = "'Name' cell must be populated for feedback email to be sent!" _
        & vbNewLine
        strTitle = "Attention!"
        iRet = MsgBox(strPrompt, vbYes, strTitle)
        If iRet = vbYes Then
        End If
    End If
    - - - - -

    Sub SendEmail()
    'Automatically creates an new email, populated with relevant data from the spreadsheet'
    
    Dim OApp As Object, OMail As Object, signature As String
    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)
        With OMail
        .Display
        End With
        
        With OMail
        signature = OMail.body
        
        .ReadReceiptRequested = True
        .To = Range("F2")
        .cc = Range("AC131") & ";" & Range("AC133")
        .Importance = 2
        .Subject = Range("F2") & "'s" & " " & Range("AC118") & " " & "Call" _
        & " " & Range("AB118") & " " & "Coaching Feedback"
        
        .body = "Hi" & " " & Range("P131") & vbNewLine & vbNewLine _
        & "Here is the feedback from the call I have assessed for you today..." & vbNewLine & vbNewLine _
        & "Date of Call:" & " " & Range("AB6") & vbNewLine _
        & "Time of Call:" & " " & Format(Range("AB8"), "hh:mm:ss") & vbNewLine & vbNewLine _
        & Range("O63") & vbNewLine & vbNewLine _
        & "If you have any questions regarding the above, or would like to discuss anything further, please let me know." & vbNewLine & vbNewLine _
        & "Regards," & vbNewLine & vbNewLine _
        & Range("W131") & signature
        .Display
         
        End With
        
    Set OMail = Nothing
    Set OApp = Nothing
    
    End Sub
    So if "F2" is blank, error message appears, if it is populated, the email is generated...

    Any ideas?

    Thanks,

    PAS

  2. #2
    Forum Contributor
    Join Date
    12-14-2013
    Location
    Tilburg, Nederland
    MS-Off Ver
    Excel 2010
    Posts
    256

    Re: Need Help Combing to working VBA codes

    The combination of the two macro's.
    You may want to consider to check if the range "F2" contains a valid email address ....

    gr,
    Gerard

    Sub SendEmail()
    'Automatically creates an new email, populated with relevant data from the spreadsheet'
    
    Dim OApp As Object, OMail As Object, signature As String
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
    
    If Range("F2").Value = "" Then 'Value > " " will generate error measage if cell contains something
        strPrompt = "'Name' cell must be populated for feedback email to be sent!" _
        & vbNewLine
        strTitle = "Attention!"
        iRet = MsgBox(strPrompt, vbYes, strTitle)
        If iRet = vbYes Then      'Doesn't do anything in the macro
        End If                          ' 
        Exit Sub
    End If
    
    
    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)
        With OMail
        .Display
        End With
        
        With OMail
        signature = OMail.body
        
        .ReadReceiptRequested = True
        .To = Range("F2")
        .cc = Range("AC131") & ";" & Range("AC133")
        .Importance = 2
        .Subject = Range("F2") & "'s" & " " & Range("AC118") & " " & "Call" _
        & " " & Range("AB118") & " " & "Coaching Feedback"
        
        .body = "Hi" & " " & Range("P131") & vbNewLine & vbNewLine _
        & "Here is the feedback from the call I have assessed for you today..." & vbNewLine & vbNewLine _
        & "Date of Call:" & " " & Range("AB6") & vbNewLine _
        & "Time of Call:" & " " & Format(Range("AB8"), "hh:mm:ss") & vbNewLine & vbNewLine _
        & Range("O63") & vbNewLine & vbNewLine _
        & "If you have any questions regarding the above, or would like to discuss anything further, please let me know." & vbNewLine & vbNewLine _
        & "Regards," & vbNewLine & vbNewLine _
        & Range("W131") & signature
        .Display
         
        End With
        
    Set OMail = Nothing
    Set OApp = Nothing
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Combined Two Codes but Not working
    By bhaddya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-08-2013, 01:59 PM
  2. Codes not working in worksheet
    By bodmas in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-24-2011, 08:55 AM
  3. Working out Ave when #div/0 codes
    By TrainerJ in forum Excel General
    Replies: 6
    Last Post: 12-11-2009, 06:19 AM
  4. [SOLVED] Working with Access Dabatabases through VBA Codes in Excel
    By Dennis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2005, 05:05 PM

Tags for this Thread

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