edit outlook email based on values in excel

drewbny

Board Regular
Joined
Jan 16, 2011
Messages
98
Each month i have a standard email in outlook that i write, but i have to change a bunch of numbers in the text based on data i have in excel. can i automate that process?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Yes it is possible. Here is one I "wrote" to create an email from scratch from a button push in Excel. I found most of this on the internet and then adjusted it for my needs so feel free to modify it for your use. Basically it looks through some rows in excel, builds a collection of information, builds an email from scratch and outputs the collection one by one into unique emails. I stopped short of having it hit send so I could review the emails, but that is pretty easy as I remember. I hope this gives you a starting point.

VBA Code:
Sub SendForChanges()

Dim colFiles As Collection
Dim changeDoc As New clsDoc ' a class variable I created
Dim myDoc As clsDoc ' a class variable I created

Dim bStarted As Boolean
Dim oOutlookApp As Object
Dim oItem As Object
Dim pStr As String
    
    On Error Resume Next

    myExcel = ActiveWorkbook.Name
    myPath = ActiveWorkbook.Path
    myName = Workbooks(myExcel).Sheets("Changes List").Range("F1").Value
    
    Set colFiles = New Collection
    
    'Get list of docs and changes from Excel
    myRows = Cells(Rows.Count, 2).End(xlUp).Row
    For i = 1 To myRows
        If LCase(Range("A" & i).Value) = "x" Then
            Set changeDoc = New clsDoc
            changeDoc.Name = Range("B" & i).Value
            changeDoc.Changes = Range("C" & i).Value
            changeDoc.Rev = Range("D" & i).Value
            colFiles.Add changeDoc
        End If
    Next i
        
    ' Loop through the collection and output the information
    For Each myDoc In colFiles
        
            'Get Outlook if it's running
            Set oOutlookApp = GetObject(, "Outlook.Application")
        '    If Err <> 0 Then
        '        'Outlook wasn't running, start it from code
        '        Set oOutlookApp = CreateObject("Outlook.Application")
        '        bStarted = True
        '    End If
        
            'Create a new mailitem
            Set oItem = oOutlookApp.CreateItem(olMailItem)
        
        
            With oItem
                .CC = ""
                .BCC = ""
                .Subject = myDoc.Name & " revision"
                .Body = "Please see the attached " & myDoc.Name & ".  Please italicize all changes that you make to the document." & _
                    Chr(10) & "Please provide a simple bulleted list of the changes."
                .Body = .Body & Chr(10) & Chr(10)
                .Body = .Body & "Sincerely," & Chr(10) & myName
                .Display
            End With
                
        '    If bStarted Then
        '        'If we started Outlook from code, then close it
        '        oOutlookApp.Quit
        '    End If
        
            'Clean up
            Set oItem = Nothing
            Set oOutlookApp = Nothing
    
    Next myDoc

End Sub
 
Upvote 0
My code has a Class Variable that you would need to take out. Also, that code is specific to the instance I was working on. You will have to change the code to meet your requirements. Specifically, you will have to write the section that reads the data from the correct Excel references and then change the output text for your email.

I only provided this to give you the pieces needed to make this work. It isn't a drop-in because you haven't provided enough information to write a drop-in.
 
Upvote 0
My code has a Class Variable that you would need to take out. Also, that code is specific to the instance I was working on. You will have to change the code to meet your requirements. Specifically, you will have to write the section that reads the data from the correct Excel references and then change the output text for your email.

I only provided this to give you the pieces needed to make this work. It isn't a drop-in because you haven't provided enough information to write a drop-in.
what is a drop-in?
 
Upvote 0
Sorry. I just meant you can't copy and paste my code directly into your code window and expect it to work (ie you can't drop it in). It has the pieces you need, but it needs to be modified to work for your case. You need to update where the data is pulled from and you need to formulate the email as well.
 
Upvote 0
Sorry. I just meant you can't copy and paste my code directly into your code window and expect it to work (ie you can't drop it in). It has the pieces you need, but it needs to be modified to work for your case. You need to update where the data is pulled from and you need to formulate the email as well.
ok thanks!!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top