Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Extract multiple embedded MSG files from a Word document.

Posted on 2008-10-02
8
Medium Priority
?
1,310 Views
Last Modified: 2011-10-19
Hello all :)

Hope someone can help.

I have a Word document which is currently version 2003 but can be saved in 2007 (.docx). Within the document are around 900 .msg files which now need to be extracted into a folder. I've tried highlighting them all and copy/paste into a folder but all I get is a Scrap file. If I select each one and copy/paste then it saves correctly.

Obviously, manually selecting each one and copy/pasting will take ages. I've also tried saving the document as a .docx and renaming it to a ZIP file in-order to look at the contents. However, the embedded .msg files are showing as .bin files.

I'd guess that the only way to do this is to code some sort of macro which can highlight, copy, paste (to folder) and highlight next one and repeat.

Can anyone assist me further?

Please note: these .msg files are actually Outlook contact cards. When you double click them they do open correctly in Outlook as a contact card. Just in case this is important.

Many thanks in advance :)
0
Comment
Question by:Boyderama
[X]
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
  • 4
  • 4
8 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22622402
Can you pls post an example - ie with just a few of the addresses

Regards

Dave
0
 

Author Comment

by:Boyderama
ID: 22622476
Attached as requested. Thanks!
Example.doc
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22623260
I ran this code over the sample file an it extrcated all four msg's into a directory, C:\mytmp

to run the code
Tools .. Macros .. Macro
and click
Runme

pls alter your folder path first

I did set a reference to the Outlook Object
- press ALt & F11
- Tools ... References
- tick the box next to Microsoft Outlook XX object Library

This reference should be set already  when you open the altered sample file below

Cheers

Dave

Sub RunMe()
    Dim olApp As Outlook.Application, x As Outlook.Inspector
    Set olApp = New Outlook.Application
    For Each obj In ActiveDocument.InlineShapes
        Set objole = obj.OLEFormat
        objole.DoVerb (wdOLEVerbShow)
        Set x = olApp.inspectors(1)
        'alter path below   
        x.CurrentItem.SaveAs "c:\mytmp\" & x.Caption & ".msg"
        SendKeys "{ESC}"
        x.Close (olDiscard)
    Next
End Sub

Open in new window

Example-1-.doc
0
Independent Software Vendors: 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!

 

Author Comment

by:Boyderama
ID: 22623378
I'm getting an error:

Microsoft Visual Basic

"Array index out of bounds."

Tried this in Office 2007 running on Vista and Office 2003 running XP in a VM.

I'd created a folder called c:\mytmp and double checked Microsoft Outlook 12 object Library was ticked. (11 for Office 2003).

Any ideas? Thank you very much for your help so far. Very kind :)
0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 2000 total points
ID: 22624046
When I steped through this code in the VBE it worked, but running from the menu I had the same error you did

I have modified the approach below, this tested fine for me once I went back to late binding on Outlook. I suggest that you run this with Outlook alraedy open

Cheers

Dave
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 
Sub RunMe()
    Dim olApp As Object, x As Object
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")
  
    'close any existing Outlook windows
    For Each x In olApp.inspectors
        x.Close (olDiscard)
    Next
 
    For Each obj In ActiveDocument.InlineShapes
        Set objole = obj.OLEFormat
        Debug.Print objole.IconLabel
        objole.DoVerb (wdOLEVerbShow)
        SendKeys "{ESC}"
        Sleep 1000
        DoEvents
        For Each x In olApp.inspectors
            Debug.Print x.Caption
            x.CurrentItem.SaveAs "c:\mytmp\" & x.Caption & ".msg"
            x.Close (olDiscard)
        Next
    Next
End Sub

Open in new window

0
 

Author Comment

by:Boyderama
ID: 22632212
Fantastic! It failed a few times as some of the contact names had a \ or / in them. It was trying to name the file with an illegal symbol. Once I'd deleted those symbols it worked without a problem.

Dave, thank you very much for taking your time to help me. Not only did you save me a great deal of time by automating the process you also taught me some VB code :)

0
 

Author Closing Comment

by:Boyderama
ID: 31502295
Brilliant! Quick turnaround and VB code worked a treat. So kind and helpful. Thanks so much!
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22632231
No probs. :)

I enjoyed this one as it was quite different - my google search turned up a fix for embedded xls objects but there wasn't anything I could find on extracting msg files. So I picked up a few new tricks on this one as well

Cheers

Dave
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

688 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