Results 1 to 4 of 4

changing date in email subject line with vba

Threaded View

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    51

    changing date in email subject line with vba

    Hi people.

    Guys, i need help with adding a date to the subject line in outlook. basically when I click a button in excel I would like a populated email come up. But what I need to do is have the subject heading date change so it has the previous months date. ie November 2012. Could someone please show me how to do this?

     Sub runMail()
    
    Call OutlookMailSender
    
    End Sub
    
    Sub OutlookMailSender(Optional attachment)
    
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.recipient
    Dim objOutlookAttach As Outlook.attachment
    Dim bodytext As String
    Dim recipient As String
    Dim mBefore As Date
    
    
    bodytext = "Hi " & vbNewLine & vbNewLine & vbNewLine & _
    "This email was sent by Excel automation"
    
    recipient = "[email protected]"
        
    
    Set objOutlook = CreateObject("Outlook.Application")
    
    
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
    With objOutlookMsg
    
    Set objOutlookRecip = .Recipients.Add(recipient)
    objOutlookRecip.Type = olTo
    
    
    Set objOutlookRecip = .Recipients.Add("[email protected]")
    objOutlookRecip.Type = olCC
    
    
    Set objOutlookRecip = .Recipients.Add("[email protected]")
    objOutlookRecip.Type = olBCC
    
    
    .Subject = "HELLO"
    .Body = bodytext
    .Importance = olImportanceHigh
    
    
    If Not IsMissing(attachment) Then
    Set objOutlookAttach = .Attachments.Add(attachment)
    End If
    
    For Each objOutlookRecip In .Recipients
    
    If Not objOutlookRecip.Resolve Then MsgBox "Could not resolve the email for " & objOutlookRecip
    Next
    
    If True Then
    .Display
    Else
    
    .Save
    .Send
    End If
    
    End With
    
    Set objOutlook = Nothing
    
    
    End Sub
    Last edited by ConfusedaboutVBA; 12-09-2012 at 06:35 AM.

Thread Information

Users Browsing this Thread

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

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