'convert msg to html in background using vbscript
I'm converting an Outlook msg file to an html file. So far I have:
Dim objshell,BaseName,outlookapp,emailPath
Set objshell= CreateObject("scripting.filesystemobject")
Set outlookapp = CreateObject("Outlook.Application")
Set email = outlookapp.CreateItemFromTemplate(emailPath)
emailPath = "C:\Users\makkerman\Desktop\email folder\test.msg"
BaseName = objshell.GetBaseName(emailPath)
email.saveas objshell.GetParentFolderName(emailPath) & "\" & BaseName & ".html", 5
outlookapp.Quit
I'd like this to run in the background (without disturbing the user who runs it). Do I have to start an Outlook process? As it currently stands, if the user has Outlook open, then the above script closes Outlook and I can understand why (outlookapp.Quit). If Outlook isn't open when the script is run, Outlook opens for the script's duration.
Can someone please nudge me in the right direction? Thank you!
Solution 1:[1]
Why do you need to call Application.Quit? If Outlook was running, it will stay running. If it was not running, Outlook will close itself when you de-reference all Outlook objects - keep in mind that Outlook is a singleton and CreateObject will connect to the already running instance; you do not get a brand new process.
If you do not want to use Outlook, you can use Redemption (I am its author, it will not start Outlook):
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.GetMessageFromMsgFile("c:\temp\test.msg")
Msg.SaveAs "c:\temp\test.html", 5
Solution 2:[2]
I would create an instance of Outlook regardless if it's open or not. This should help: Run program minimized. Make sure to check out the docs link in the answer to get all parameter options.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Community |
