vb code to copy to excel or word item/items from inbox

Posted on 2005-03-04
Medium Priority
Last Modified: 2010-05-18
I would like to copy the selected document in my inbox to an excel or word document.
Is that possible?
Question by:zachvaldez
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 76

Expert Comment

by:David Lee
ID: 13463835
Hi zachvaldez,
> selected document

Do you mean the selected message?  Or are you talking about an attachment?


Author Comment

ID: 13464592
selected message
LVL 76

Expert Comment

by:David Lee
ID: 13466026
Then I think I can do that.  I'll post the code within the next 24 hours.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 76

Accepted Solution

David Lee earned 1000 total points
ID: 13472595

Well, I'm a little late, but here's the code.  This macro will copy the body of the selected message into a new Word document.  Here's what you'll need to do to use the macro.
1.  Open Outlook
2.  Click Tools->Macros->Visual Basic Editor
3.  If not already expanded, expand Modules and click on Module1
4.  Copy the code below and paste it into the right-hand pane of the VB Editor
5.  Click the diskette icon on the toolbar to save the code
6.  Close the VB Editor
7.  Select a message and run the macro

'Macro begins here
Sub OpenSelectedMessageInWord()
    Dim objSelectedItems As Outlook.Selection, _
        objMessage As Outlook.MailItem, _
        objItem As Object, _
        objWordApp As Word.Application, _
        objWordDoc As Word.Document
    Set objSelectedItems = Application.ActiveExplorer.Selection
    If objSelectedItems.Count > 0 Then
        Set objWordApp = CreateObject("Word.Application")
        For Each objItem In objSelectedItems
            If objItem.Class = olMail Then
                Set objMessage = objItem
                Set objWordDoc = objWordApp.Documents.Add(, , 0)
                objWordDoc.Content.InsertAfter objMessage.Body
                objWordApp.Visible = True
            End If
    End If
    Set objItem = Nothing
    Set objMessage = Nothing
    Set objSelectedItems = Nothing
    Set objWordDoc = Nothing
    Set objWordApp = Nothing
End Sub
'Macro ends here

Author Comment

ID: 13478727
Ok that worked! I'll raise for another 100 points .
I'd like a template in word that would accept the following bookmarks from outlook to continue what we outputted above.
the word doc created should come from a template

Outlook>>    Word template
From:>>> From
Body:>>>> Body

There should be a header/footer area in the template to include a Date field.

In the footer shold be able to attached any attachments

LVL 76

Expert Comment

by:David Lee
ID: 13482233

Sorry, I'm not good enough with the Word object model to manage that.  

Author Comment

ID: 13482746
OK I'll take the first answer because it answered that question! you have extra points for honesty..
LVL 76

Expert Comment

by:David Lee
ID: 13482977

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question