Insert a File

Discussion in 'Microsoft Outlook VBA Programming' started by Mike Faulkner, Mar 15, 2010.

  1. Hello

    App: Outlook 2003
    OS: Windows XP

    I would like to create some VBA which would insert a file into the Body of
    the email.

    Set NewEmail = CreateItem(olMailItem)
    With NewEmail
    .Subject = "Test 1"
    .Body = "<Insert a file... 'c:\pelikan\newsletter\Email_01.htm'>"
    End With


    The HTM file contains a graphic and Webite hyperlinks etc. Any assistance
    would be greatly appreciated.

    Kind Regards
    Mike Faulkner, Mar 15, 2010
    1. Advertisements

  2. What do you mean by "insert a file"? Do you want to insert the contents of a
    file or to insert an attachment of a file? If you want to insert text from a
    file you need to read the file contents as a string and insert that into the
    HTMLBody property. Body is for plain text and knows nothing of HTML.
    Ken Slovak - [MVP - Outlook], Mar 15, 2010
    1. Advertisements

  3. Ken

    I want to code the following:

    In a new email click on:
    1. Insert|File
    2. Choose a file
    3. Choose 'Insert as Text' from 'Insert' button

    Mike Faulkner, Mar 15, 2010
  4. How you'd do that depends on how you want to code it. If you want to use
    the standard Outlook buttons you would handle the MailItem.AttachmentAdd()
    event. That provides a handle to the added attachment. You would save that
    to the file system and open and read it as a text string. How you'd do that
    would depend on the type of file that was being attached.

    I'd start by searching at for code samples for reading
    files and attaching file contents, as well as for modifying the HTMLBody of
    mail items.
    Ken Slovak - [MVP - Outlook], Mar 15, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.