WallyZ
11-26-2015, 06:26 PM
I trying to open a custom form message saved to disk but all I get a blank message. The message header appears correct so I assume I have got the correct message.
When opening the same custom form msg from Explorer it all works fine.
Here is the code:
Private Sub PrintPreviewCustomFormMsgFromSavedDiskFile_Click()
Dim oOLapp As Outlook.Application
Dim oMapi As Outlook.NameSpace
Dim oInspector As Outlook.Inspector
Dim oCB As Office.CommandBars
Dim oItem As Outlook.MailItem
Dim MyPath As String
MyPath = "C:\temp\Custom Form Example 1.msg" ' Form opens/displays correctly from Explorer
Set oOLapp = GetObject(, "Outlook.Application")
Set oMapi = oOLapp.GetNamespace("MAPI")
Set oItem = oMapi.OpenSharedItem(MyPath) ' Either this or the next ...
Set oItem = oOLapp.Session.OpenSharedItem(MyPath) ' but not both of course
oItem.Display ' Displays blank message ?
Set oInspector = oOLapp.ActiveInspector
Set oCB = oInspector.CommandBars
oCB.ExecuteMso ("FilePrintPreview") ' A blank message results in a blank preview !
Set oCB = Nothing
Set oInspector = Nothing
End Sub
Any ideas how this should be done correctly?
When opening the same custom form msg from Explorer it all works fine.
Here is the code:
Private Sub PrintPreviewCustomFormMsgFromSavedDiskFile_Click()
Dim oOLapp As Outlook.Application
Dim oMapi As Outlook.NameSpace
Dim oInspector As Outlook.Inspector
Dim oCB As Office.CommandBars
Dim oItem As Outlook.MailItem
Dim MyPath As String
MyPath = "C:\temp\Custom Form Example 1.msg" ' Form opens/displays correctly from Explorer
Set oOLapp = GetObject(, "Outlook.Application")
Set oMapi = oOLapp.GetNamespace("MAPI")
Set oItem = oMapi.OpenSharedItem(MyPath) ' Either this or the next ...
Set oItem = oOLapp.Session.OpenSharedItem(MyPath) ' but not both of course
oItem.Display ' Displays blank message ?
Set oInspector = oOLapp.ActiveInspector
Set oCB = oInspector.CommandBars
oCB.ExecuteMso ("FilePrintPreview") ' A blank message results in a blank preview !
Set oCB = Nothing
Set oInspector = Nothing
End Sub
Any ideas how this should be done correctly?