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

x
?
Solved

Saving .msg files to .doc +vb6.0

Posted on 2009-05-12
16
Medium Priority
?
847 Views
Last Modified: 2012-05-06
Hi,
Can anyone please suggests on how can I save .msg files to .doc +vb6.0
0
Comment
Question by:RIAS
[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
  • 9
  • 6
16 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24363740
Have a look at the following:

http://www.bestshareware.net/download/outlook-eml-and-msg-converter.htm

Good Luck!

Gary
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 24363916
Hi, RIAS.

Outlook can save messages directly into .doc format.  There's a caveat to that though.  Here's what Microsoft says on this: "Also note that even though olDoc is a valid OlSaveAsType constant, messages in HTML format cannot be saved in Document format, and the olDoc constant works only if Microsoft Word is set up as the default email editor."  If you are usign Outlook 2003 or earlier, then using Word as the email editor is an option.  If using Outlook 2007, then Word is the email editor, there is not option to use anything else.  Here's how you'd save a message into .doc format

objMessage.SaveAs "Some File Name", olDoc

You can also save items into Rich-text format (.rtf) and then open them in Word and save in .doc format.  To save a message in .rtf format, change olDoc to olRTF in the code sample.
0
 

Author Comment

by:RIAS
ID: 24364313
Hi,
THe problem is I have .msg files in folder so not using outlook.exe directly..any suggestions on objMessage.SaveAs "Some File Name", olDoc


Cheers
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:RIAS
ID: 24364327
Hi tbsgad,


Can you please copy and paste the code in here as cannot access this url ..security issue


Cheers
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24364390
Open the message in Outlook using the code I posted to your other question, then use the command above to save to .doc format.  Unless you are going to learn enhanced MAPI programming, then the only way I know of to read a .msg file is using Outlook.  There may be 3rd-party programs that use enhanced MAPI to read .msg files without Outlook, the one Gary linked to appears to require Outlook, but I'm not familiar with any.
0
 

Author Comment

by:RIAS
ID: 24364431
oki mate will try .....
0
 

Author Comment

by:RIAS
ID: 24365355
Hi,
Tried it but it doesnt convert it to doc format it saves it as file type

Code used:
olkMsg.SaveAs Foldername & olkMsg.Subject, olDoc


Am I  going wrong somewhere?

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24365674
Sorry, typo.  I omitted the extension.  Use this instead

    olkMsg.SaveAs Foldername & olkMsg.Subject & ".doc", olDoc
0
 

Author Comment

by:RIAS
ID: 24366301
Hi,
Sorry no luck ..it errrors
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24366376
What's the error?
0
 

Author Comment

by:RIAS
ID: 24372214
Hi,
It justs jumps out of the function on that linedon't really know

Cheers
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24372955
So it just stops running and doesn't display any error messages?
0
 

Author Comment

by:RIAS
ID: 24373481
Yup..it jumps out of the function
0
 

Author Comment

by:RIAS
ID: 24373538
Hi,
Manage to save it in txt ile thats fine..you r previous solution did work.thanks for that.
Now I need to set a printer which is different from default printer how do i  set it and get the .msg file printed with all its attachments in vb.

I tried your solution on other qustions:

Public Sub PrintMessagesAndAttachments()
    Dim objFSO As Object, _
        objFolder As Object, _
        objFile As Object, _
        objTempFolder As Object, _
        olkMsg As Object, _
        olkAttachment As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFolder = objFSO.GetSpecialFolder(2)
    'Change the folder path on the following line'
    Set objFolder = objFSO.GetFolder("C:\eeTesting")
    For Each objFile In objFolder.Files
        If objFSO.GetExtensionName(objFile.Path) = "msg" Then
            ShellExecute 0&, "print", objFile.Path, 0&, 0&, 0&
            Set olkMsg = Application.CreateItemFromTemplate(objFile.Path)
            For Each olkAttachment In olkMsg.Attachments
                olkAttachment.SaveAsFile objTempFolder & "\" & olkAttachment.fileName
                ShellExecute 0&, "print", objTempFolder & "\" & olkAttachment.fileName, 0&, 0&, 0&
            Next
        End If
    Next
    Set objFSO = Nothing
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objTempFolder = Nothing
    Set olkMsg = Nothing
    Set olkAttachment = Nothing
End Sub

but it errors on the line
    Set olkMsg = Application.CreateItemFromTemplate(objFile.Path)

Should I post another question for this?


Cheers

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24403087
No need to open another question.  Here's the code for printing to a specific printer.
Sub PrintAttachmentToSpecificPrinter(Item As Outlook.MailItem)
    Dim wshNet As Object, _
        strCurrentDefault As String, _
        objFSO As Object, _
        objTempFolder As Object, _
        olkAttachment As Outlook.Attachment
    strCurrentDefault = GetDefaultPrinter()
    Set wshNet = CreateObject("Wscript.Network")
    'Change the printer name on the next line to that of the printer you want attachments printed to
    wshNet.SetDefaultPrinter "Microsoft Office Document Image Writer"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFolder = objFSO.GetSpecialFolder(2)
    For Each olkAttachment In Item.Attachments
        olkAttachment.SaveAsFile objTempFolder & "\" & olkAttachment.FILENAME
        ShellExecute 0&, "print", objTempFolder & "\" & olkAttachment.FILENAME, 0&, 0&, 0&
    Next
    wshNet.SetDefaultPrinter strCurrentDefault
    Set wshNet = Nothing
    Set objFSO = Nothing
    Set objTempFolder = Nothing
    Set olkAttachment = Nothing
End Sub
 
Function GetDefaultPrinter() As String
    Dim strPrinter As String, _
        intReturn As Integer
    strPrinter = Space(255)
    intReturn = GetProfileString("Windows", ByVal "device", "", strPrinter, Len(strPrinter))
    If intReturn Then
        strPrinter = UCase(Left(strPrinter, InStr(strPrinter, ",") - 1))
    End If
    GetDefaultPrinter = strPrinter
End Function

Open in new window

0
 

Author Comment

by:RIAS
ID: 24403502
Cheers mate
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Make the most of your online learning experience.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

715 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