Reply using a saved Outlook Message file (.msg) (AC2007) (1 Viewer)

AOB

Registered User.
Local time
Today, 03:04
Joined
Sep 26, 2012
Messages
615
Hi guys,

Anybody know if it's possible to create a reply to an e-mail if the 'source' e-mail is saved locally as a .msg file (as opposed to using a mailitem directly from an Outlook folder)

Here is as far as I've gotten...

Code:
Private appOutlook As Object          [COLOR=darkgreen]' Outlook Application[/COLOR]
Private objNameSpace As Object        [COLOR=darkgreen]' Outlook NameSpace[/COLOR]
 Private objFolder As Object          [COLOR=darkgreen]' Outlook Folder[/COLOR]
  
 Public Sub ReplyToEMail(strSourceEMail As String)
  
     On Error GoTo ErrorHandler
  
     Dim objExplorer As Object
     Dim objMailItem As Object
     Dim objMailResponse As Object
  
     Set appOutlook = CreateObject("Outlook.Application")
  
     If Not appOutlook.Explorers.Count > 0 Then
  
         [COLOR=darkgreen]' Need to open Outlook 'visibly' for the new MailItem to be retained without error[/COLOR]
  
         Set objNameSpace = appOutlook.GetNamespace("MAPI")
         Set objFolder = objNameSpace.GetDefaultFolder(6)            [COLOR=darkgreen]' olFolderInbox[/COLOR]
         Set objExplorer = appOutlook.Explorers.Add(objFolder, 0)    [COLOR=darkgreen]' olFolderDisplayNormal[/COLOR]
  
         With objExplorer
  
             .Activate
             .WindowState = 0                                        [COLOR=darkgreen]' olMaximized
[/COLOR]             .WindowState = 1                                        [COLOR=darkgreen]' olMinimized
[/COLOR]
         End With
    
    End If
    
    Set objMailItem = appOutlook.CreateItemFromTemplate(strSourceEMail)
    [COLOR=red]Set objMailResponse = objMailItem.Reply[/COLOR]
  
     With objMailResponse
  
         [COLOR=darkgreen]' ....further work to go here...[/COLOR]
It bombs out on the line in red :

Error -2147352567
Could not send the message
(I'm not trying to fire the reply out straight away, merely set up the reply for the user to review and send if appropriate...)

Any suggestions?
 

AOB

Registered User.
Local time
Today, 03:04
Joined
Sep 26, 2012
Messages
615
Figured it out... Hope this helps somebody else...

Code:
Public Sub ReplyToEMail(strSourceEMail As String)
  
     Dim appOutlook As Object
     Dim objMailItem As Object
     Dim objMailResponse As Object
  
     Set appOutlook = CreateObject("Outlook.Application")
     Set objMailItem = [COLOR=red]appOutlook.Session.OpenSharedItem(strSourceEMail)[/COLOR]
     Set objMailResponse = objMailItem.Reply
  
     With objMailResponse
  
         ....
 

Mattmcrae

New member
Local time
Yesterday, 21:04
Joined
Dec 25, 2022
Messages
1
Figured it out... Hope this helps somebody else...

Code:
Public Sub ReplyToEMail(strSourceEMail As String)
 
     Dim appOutlook As Object
     Dim objMailItem As Object
     Dim objMailResponse As Object
 
     Set appOutlook = CreateObject("Outlook.Application")
     Set objMailItem = [COLOR=red]appOutlook.Session.OpenSharedItem(strSourceEMail)[/COLOR]
     Set objMailResponse = objMailItem.Reply
 
     With objMailResponse
 
         ....
Not sure if you're still on this forum after all these years, but thanks for this excellent code.
 

Users who are viewing this thread

Top Bottom