Outlook script to export /copy email data

Have you tried selecting an email in Outlook and copying it to learn that it copies the entire .msg file instead of just the raw data such as the subject line or just the sender? Perhaps you want to create a log of emails from certain senders so you can categorize the emails in Excel or just have a printed record. Here’s a handy visual basic for application(VBA) script that does this. I tested this with a folder of over 2,000 emails and it works well. It will likely take a while to execute if select a folder with a large number of emails. To use this code, you’ll have to create a macro in Outlook. Note, the output will be sent to the immediate window. This is similar to the debugging window in Outlook.

Sub PrintSubjectLineForSelectedFolder()
  
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim msg As Object
 Dim myItems As Outlook.Items

Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)

    Dim objFolderSelected As Folder
     Set objFolderSelected = objNS.PickFolder
    If TypeName(objFolderSelected) <> "Nothing" Then
    
        Debug.Print objFolderSelected
        Set olFolder = objFolderSelected
        'Set olFolder = olFolder.Folders("Test Results")' can also be hardcoded
      
        For Each msg In olFolder.Items

'Debug.Print TypeName(msg)
    If msg Is Nothing Then
'If varValue = Nothing Then

        Exit For
   
	Else

    If Not msg Is Nothing Then
 
        Debug.Print msg.Subject
        
       
   End If
   
   End If
   
Next

    Else
    
        Debug.Print vbCr &amp; "User selected Cancel No Folder selected"
    End If

    Set objFolderSelected = Nothing
    Set objNS = Nothing

End Sub