Post email data to the Web
April 8, 2009 • JP • No Comments • Rate This Article![]()
In Outlook VBA macro to post email body to the web, Jeremy Slade posts an Outlook macro to publish emails to a web server.
The code uses the XMLHTTP Object to send POST data to a specified URL. I'm not familiar with the actual site being used, but the XMLHTTP object leads me to believe the interface is super fast.
If an email slips through the script rule, however, you'll be stuck writing code that imports the message manually. So I've taken the liberty of doing so myself.
This code will call Jeremy's PublishMsgToWeb macro on a selected or opened message, so you can process any email manually. You can either run it after selecting an email in a folder (ActiveExplorer.Selection.Item(1)) or after opening the message for display (ActiveInspector.CurrentItem).
Dim Msg As Outlook.MailItem
' set reference to open/selected mail item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set Msg = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set Msg = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If Msg Is Nothing Then GoTo ExitProc
Call PublishMsgToWeb(Msg)
ExitProc:
End Sub
Come to think of it, setting a reference to Msg like this is pretty common, so here's an encapsulated function that does it:
' returns MailItem object reference to open/selected mail item
' if any error occurs, just exit
On Error GoTo ExitProc
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set GetMessage = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetMessage = ActiveInspector.CurrentItem
Case Else
End Select
ExitProc:
End Function
Usage:
Dim msg As Outlook.MailItem
Set msg = GetMessage
If Msg Is Nothing Then GoTo ExitProc
Call PublishMsgToWeb(Msg)
ExitProc:
End Sub
Previous Post: Update to Data Filter Tool
Next Post: Excel Tutorial Series – VBA Macros, Part One Of Two




Speak Your Mind
Tell us what you're thinking...Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].