Get Previous Month and Add in Outlook email subject

VeeBa

Board Regular
Joined
Apr 22, 2017
Messages
82
Hi All - Can you please help me with the below code? I am trying to send an outlook email (everything is working fine) except for the subject part. I wanted to include the previous month in the subj. For example, today is May month. I want my subject to be "Apr Salary Report". I have found this line = Dateadd("m",-1, Date) but I only need the month, not exactly the full date.. Any help is appreciated, thanks in advance! :)

Code:
FNm1 = Worksheets("Names").Cells(i, 1).Value

[B]Subject1 = " Salary Report - " & FNm1[/B]
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
.
Here is a sample macro :

Code:
Option Explicit


Sub mailchart()
Dim OutApp As Object
Dim OutMail As Object
Dim vInspector, GetInspector, wEditor As Variant




Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


lm = Format$(DateAdd("m", -1, Now()), "mmmm")


With OutMail
    .To = "yo momma@nowhere.com"
    .CC = "xyz@anc.com"
    .BCC = "abc@xyz.com"
    .Subject = lm & " Salary Report"
    .Body = "Dear" & "Macro " & vbCrLf
    .Display
    ActiveSheet.Range("G11:N26").Copy
    Set vInspector = OutMail.GetInspector
    Set wEditor = vInspector.WordEditor


    wEditor.Application.Selection.Start = Len(.Body)
    wEditor.Application.Selection.End = wEditor.Application.Selection.Start


    wEditor.Application.Selection.Paste


.Display
End With
End Sub

I used the variable lm for last month. The code line at top is : lm = Format$(DateAdd("m", -1, Now()), "mmmm")

The .Subject line is : .Subject = lm & " Salary Report"
 
Upvote 0

Forum statistics

Threads
1,221,579
Messages
6,160,616
Members
451,658
Latest member
NghiVmexgdhh

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