Craeting Outlook Message in Draff message not working through Excell VBA
-
Mittwoch, 1. August 2012 07:56
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.MailItemSet 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 withend 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 ?
Alle Antworten
-
Mittwoch, 1. August 2012 08:24
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.- Als Antwort vorgeschlagen Brian Skinn Mittwoch, 1. August 2012 19:05
- Als Antwort markiert Quist ZhangMicrosoft Contingent Staff, Moderator Donnerstag, 2. August 2012 09:14
-
Mittwoch, 1. August 2012 10:06
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.
-
Donnerstag, 2. August 2012 18:39
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!

