How to automatically fill email subject with attachment name in Outlook?
For those who are accustomed to using the attachment name as the subject of an email in Outlook, manually typing the attachment name in the subject line each time will be time-consuming. As shown in the gif below, if you want to fill the email subject line with the attachment name automatically when you insert an attachment, the VBA method in this tutorial will help.
Automatically fill the email subject with the attachment name with VBA code
Please run the following VBA code to automatically fill the email subject with the name of the inserted attachment in Outlook.
1. Launch your Outlook, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, double click Project1 (VbProject.OTM) > Microsoft Outlook Objects > ThisOutlookSession to open the ThisOutlookSession (Code) editor.
3. Then copy the following VBA code into the ThisOutlookSession (Code) editor.
VBA code: Autofill the email subject with the attachment name
Public WithEvents GExplorer As Explorer
'Updated by Extendoffice 20220926
Public WithEvents GInspectors As Inspectors
Public WithEvents GMail As MailItem
Private Sub Application_Startup()
Set GExplorer = Application.ActiveExplorer
Set GInspectors = Application.Inspectors
End Sub
Private Sub GExplorer_InlineResponse(ByVal Item As Object)
Set GMail = Item
End Sub
Private Sub GInspectors_NewInspector(ByVal Inspector As Inspector)
Dim xItem As Object
Set xItem = Inspector.CurrentItem
If xItem.Class <> olMail Then Exit Sub
Set GMail = xItem
End Sub
Private Sub GMail_AttachmentAdd(ByVal Att As Attachment)
Dim xFileName As String
On Error Resume Next
If VBA.Trim(GMail.Subject) <> "" Then Exit Sub
If MsgBox("Do you want to use the attachment name as the subject?", vbYesNo + vbInformation, "Kutools for Outlook") = vbNo Then Exit Sub
xFileName = Att.DisplayName
xFileName = Left$(xFileName, VBA.InStrRev(xFileName, ".") - 1)
GMail.Subject = xFileName
End Sub
4. Now you need to save the code and restart Outlook.
5. From now on, when you insert an attachment in an email that doesn't have a subject filled in yet, a Kutools for Outlook dialog box will pop up asking you if you want to use the attachment name as the subject, click the Yes button.
Then the subject line will be populated with the name of the inserted attachment automatically.
Notes:
AI Mail Assistant in Outlook: Smarter Replies, Clearer Communication (one-click magic!) FREE
Streamline your daily Outlook tasks with the AI Mail Assistant from Kutools for Outlook. This powerful tool learns from your past emails to offer intelligent and accurate responses, optimize your email content, and help you draft and refine messages effortlessly.

This feature supports:
- Smart Replies: Get responses crafted from your past conversations—tailored, precise, and ready to go.
- Enhanced Content: Automatically refine your email text for clarity and impact.
- Effortless Composition: Just provide keywords, and let AI handle the rest, with multiple writing styles.
- Intelligent Extensions: Expand your thoughts with context-aware suggestions.
- Summarization: Get concise overviews of long emails instantly.
- Global Reach: Translate your emails into any language with ease.
This feature supports:
- Smart email replies
- Optimized content
- Keyword-based drafts
- Intelligent content extension
- Email summarization
- Multi-language translation
Best of all, this feature is completely free forever! Don’t wait—download AI Mail Assistant now and enjoy!
Best Office Productivity Tools
Breaking News: Kutools for Outlook Launches Free Version!
Experience the all-new Kutools for Outlook with 100+ incredible features! Click to download now!
📧 Email Automation: Auto Reply (Available for POP and IMAP) / Schedule Send Emails / Auto CC/BCC by Rules When Sending Email / Auto Forward (Advanced Rules) / Auto Add Greeting / Automatically Split Multi-Recipient Emails into Individual Messages ...
📨 Email Management: Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
📁 Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
🌟 Interface Magic: 😊More Pretty and Cool Emojis / Remind you when important emails come / Minimize Outlook Instead of Closing ...
👍 One-click Wonders: Reply All with Attachments / Anti-Phishing Emails / 🕘Show Sender's Time Zone ...
👩🏼🤝👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails / Split a Contact Group to Individual Groups / Remove Birthday Reminders ...
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!


🚀 One-Click Download — Get All Office Add-ins
Strongly Recommended: Kutools for Office (5-in-1)
One click to download five installers at once — Kutools for Excel, Outlook, Word, PowerPoint and Office Tab Pro. Click to download now!
- ✅ One-click convenience: Download all five setup packages in a single action.
- 🚀 Ready for any Office task: Install the add-ins you need, when you need them.
- 🧰 Included: Kutools for Excel / Kutools for Outlook / Kutools for Word / Office Tab Pro / Kutools for PowerPoint