none
Craeting Outlook Message in Draff message not working through Excell VBA RRS feed

  • Question

  • I'm using VBA in Excel 2010 to create outlook emails in the draft folder

    --------------------------------------------------------------------------

    Sub Test()

     dim OlookAPP as outlook.application
     dim OlookSpace as outlook.Namespace
     dim OlookDraft as outlook.MAPIFolder
     dim OlookMsg as outlook.MailItem

     Set OlookApp = new outlook.Application
     Set OlookSpace = OlookApp.GetNameSpace("MAPI")
     Set OlookDraft = OlookSpace.GetDefaultFolder(olFolderDrafts)
     Set OlookMsg = OlookDraft.items.add(Outlook.olItemType.olMailItem)

     with OlookMsg
      .save
      .to = "test@xxx.com"
      .subject = "test"
      .body = "xxxxxxxxxxxxx"
      .save
     end with

    end sub

    --------------------------------------------------------------------

    in 2007 and previous version office this work perfectly and email just created was visible in my Draft folder , in 2010, email is not in the draft folder...

    Strange : if I add .display, the email pop-up, and the current folder is draft (File->Info  :Current Folder) , if I add .send the email is sent...

    any idea of what I can do to maintain this code working in 2010 ?

    Wednesday, August 1, 2012 7:56 AM

Answers

  • you do not need to go through all the hops with draft folder - messages of type IPM.Note (olMailItem) will be by default stored in draft folder. Simply adter grabbing mapi namespace and calling Logon, call CreateItem on outlook's application object and fill it as you do, calling save at the end.
    Wednesday, August 1, 2012 8:24 AM

All replies

  • you do not need to go through all the hops with draft folder - messages of type IPM.Note (olMailItem) will be by default stored in draft folder. Simply adter grabbing mapi namespace and calling Logon, call CreateItem on outlook's application object and fill it as you do, calling save at the end.
    Wednesday, August 1, 2012 8:24 AM
  • thanks this solution work fine

    however I'm still surprise that it worked in previous version and not in 2010, I just installed and discover the difference one by one.

    Wednesday, August 1, 2012 10:06 AM
  • This is an indication that you are not logged in to a profile. Are the messages being crearted in the Inbox folder?

    As Damian suggested, add a call to OlookSpace.Logon immediately after calling GetNameSpace("MAPI").


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, August 2, 2012 6:39 PM