Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:38:22+00:00 2026-06-09T10:38:22+00:00

I hope someone can help me with this. A few months ago I was

  • 0

I hope someone can help me with this. A few months ago I was able to write a macro for Outlook 2003 to add the filenames of all the attachment in an email message, which I really need for my line of work.

However, if I switch the default editor to Word, the macro doesn’t even appear; I guess it has to be incorporated into Word’s normal.dot or something. If I add it to VB from Word, I can see the macro, but I get all sorts of errors.

Hopefully someone can point me in the right direction for this. My current macro, which works in “normal” Outlook messages (not those created with Word Editor) is this:

Sub Names()

Dim Atmt As Attachment
Dim Mensaje As Outlook.MailItem
Dim Adjuntos As String


Set Mensaje = Application.ActiveInspector.CurrentItem
Mensaje.BodyFormat = olFormatHTML
i = 0
Adjuntos = ""

For Each Atmt In Mensaje.Attachments
    'If Atmt.Size > 5 Then
    Adjuntos = "<HMTL> ** Attached file: <u> " & Atmt.FileName & " </u> </html> <br>" & vbNewLine & Adjuntos
    i = i + 1
    'End If
Next Atmt

Adjuntos = "<HMTL> <u> <b> Total number of attached files: " & i & "</u></b> </html> <br>" & Adjuntos & vbNewLine

Mensaje.HTMLBody = Adjuntos & Mensaje.HTMLBody

Set Mensaje = Nothing

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:38:24+00:00Added an answer on June 9, 2026 at 10:38 am

    The difference between the two code blocks below is simply the linking of the Outlook object library. In Outlook, this is not necessary, but from Word, you need to either include the library as a reference to your Word project, or else use late binding (the method I demonstrate below).

    Late binding links the Outlook library to an object in your code/project, OLK in this case, and allows you to use the associated functions without needing to perform any additional steps/save any additional files.

    Linking the library should also work, but since this is not a normal Word project that you can reference later/a new Word project is created for each new email, I’m thinking (though I did not test) that you would need to include the code in your Normal template, which means that code will be available on any Word document you create, unless you specify a different template.

    This may or may not be what you want to do, but if it is, then just past the Outlook code into your Normal template and link the Outlook library as a reference.


    From MS Outlook (preferred method)

    This will work, even with WORD as the email editing application, when pasted into an OUTLOOK project:

    Option Explicit 
    
    Sub Names()
    
    Dim Atmt As Attachment
    Dim Mensaje As Outlook.MailItem
    Dim Adjuntos As String
    Dim Body As String
    Dim i As Integer
    
    
    Set Mensaje = Application.ActiveInspector.CurrentItem
    Mensaje.BodyFormat = olFormatHTML
    
    Body = Mensaje.HTMLBody
    
    i = 0
    Adjuntos = ""
    
    For Each Atmt In Mensaje.Attachments
        'If Atmt.Size > 5 Then
        Adjuntos = Adjuntos & "** Attached file: <u> " & Atmt.FileName & " </u> <br>"
        i = i + 1
        'End If
    Next Atmt
    
    Adjuntos = "<u> <b> Total number of attached files: " & i & "</u></b> <br>" & Adjuntos
    
    Mensaje.HTMLBody = Left(Body, InStr(Body, "</body>") - 1) & Adjuntos & Right(Body, Len(Body) - InStr(Body, "</body>") + 4)
    
    Set Mensaje = Nothing
    
    End Sub
    

    From MS Word/Within the new mail item

    I was able to get the following to work, but you should note that I got security warnings (normal, unavoidable AFAIK) that must be pushed through with user intervention.

    Paste the below into your WORD project (open mail item) and run it. You should also be able to put this in the Normal template, but that means the macro will always be available, which may or may not be a problem for you.

    Sub Names()
    
    Dim OLK As Object 'Oulook.Application
    Dim Atmt As Object 'Attachment
    Dim Mensaje As Object 'Outlook.MailItem
    Dim Adjuntos As String
    Dim Body As String
    Dim i As Integer
    
    Set OLK = CreateObject("Outlook.Application")
    Set Mensaje = OLK.ActiveInspector.CurrentItem
    Mensaje.BodyFormat = 2 'olFormatHTML
    
    Body = Mensaje.HTMLBody
    
    i = 0
    Adjuntos = ""
    
    For Each Atmt In Mensaje.Attachments
        'If Atmt.Size > 5 Then
        Adjuntos = Adjuntos & "** Attached file: <u> " & Atmt.FileName & " </u> <br>"
        i = i + 1
        'End If
    Next Atmt
    
    Adjuntos = "<u> <b> Total number of attached files: " & i & "</u></b> <br>" & Adjuntos
    
    Mensaje.HTMLBody = Left(Body, InStr(Body, "</body>") - 1) & Adjuntos & Right(Body, Len(Body) - InStr(Body, "</body>") + 4)
    
    Set OLK = Nothing
    Set Mensaje = Nothing
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hope someone can help with this. I currently have an Add to Cart option
I hope someone can help me with this, as I'm unable to find the
Hope someone can help me out with this problem I am having. I just
Hope someone can help i cant seem to get my head around this, i
I hope someone can help me here. I'm having trouble loading this variable. Right
hope someone can help. I appreciate there are a few questions that are similar
I really hope someone can help on this because I'm learning cocoa and have
Hope someone can help with this: Am trying to delete session files on /tmp
Hope someone can help with this as it's driving me mad! I'm using Aptana
I hope someone can help with this. I have a UITableViewController and want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.