How to Auto Take the First Line of Body as Subject before Sending an Outlook Email without Subject

Some users wish Outlook to auto take the first line of the email body as the subject when sending an email which has no subject. Now, in this article, we will introduce a method to realize it via VBA code.

Multiple users frequently forget to input subject when composing and sending an email. Thus, usually, they hope that Outlook can automatically fill the subject by the first line of the email body if the outgoing email has no subject. Thereinafter, we will share an easy and handy method with you.

Auto Take the First Line of Body as Subject before Sending an Email without Subject

  1. At the very outset, launch Outlook application.
  2. Then, by following the steps in “How to Run VBA Code in Your Outlook“, you can get into VBA editor.
  3. Next, in the VBA editor, add the reference to “MS Word Object Library” with accordance to “How to Add an Object Library Reference in VBA“.
  4. Later, copy the code below into “ThisOutlookSession” project.
Private WithEvents objInspectors As Outlook.Inspectors

Private Sub Application_Startup()
    Set objInspectors = Outlook.Application.Inspectors
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
    If Inspector.CurrentItem.Class = olMail And Inspector.CurrentItem.Subject = "" Then
       Inspector.CurrentItem.Subject = " "
    End If
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMail As Outlook.MailItem
    Dim objMailDocument As Word.Document
    Dim objMailSelection As Word.Selection
 
    If TypeOf Item Is MailItem Then
       Set objMail = Item
 
       If Len(Trim(objMail.Subject)) = 0 Then
          If MsgBox("No subject! Whether to take first line as subject?", vbQuestion + vbYesNo) = vbYes Then
             Set objMailDocument = objMail.GetInspector.WordEditor
             Set objMailSelection = objMailDocument.Application.Selection
 
             objMailDocument.Range(0, 0).Select
             objMailSelection.MoveEnd wdLine
 
             'Take first line of body as subject
             objMail.Subject = objMailSelection.Text
          End If
       End If
     End If
End Sub

VBA Code - Auto Take the First Line of Body as Subject before Sending an Email without Subject

  1. After that, put cursor into “Application_Startup” subroutine and press “F5”.
  2. Finally, you can have a try.
  • At first, create and compose an email with only subject empty.
  • Then, click “Send” button.
  • Later, you’ll get a message asking if to take first line of body as subject.Message Asking If to Take First Line of Body as Subject
  • As long as you select “Yes” button, the first line of the email body will be extracted and used as subject and the email will be sent out.First Line of Body Are Used as Subject

Keep Your Outlook Data Safe

Absolutely, there are multiple significant emails and other items in your Outlook. Thus, you must be unwilling to come across Outlook data loss. Then, you have to take some actions, such as making regular data backups of your Outlook, learning to use the inbuilt repair tool to fix Outlook errors and preparing a robust external recovery utility. DataNumen Outlook Repair is a good choice due to its high PST recovery rate.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.