Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

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

I would like to copy the selected document in my inbox to an excel or word document.
Is that possible?
0
zachvaldez
Asked:
zachvaldez
  • 5
  • 3
1 Solution
 
David LeeCommented:
Hi zachvaldez,
> selected document

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

Cheers!
0
 
zachvaldezAuthor Commented:
selected message
0
 
David LeeCommented:
Then I think I can do that.  I'll post the code within the next 24 hours.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
David LeeCommented:
zachvaldez,

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
        Next
    End If
    Set objItem = Nothing
    Set objMessage = Nothing
    Set objSelectedItems = Nothing
    Set objWordDoc = Nothing
    Set objWordApp = Nothing
End Sub
'Macro ends here
0
 
zachvaldezAuthor Commented:
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

0
 
David LeeCommented:
zachvaldez,

Sorry, I'm not good enough with the Word object model to manage that.  
0
 
zachvaldezAuthor Commented:
OK I'll take the first answer because it answered that question! you have extra points for honesty..
0
 
David LeeCommented:
Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now