Adding a post to an Outlook Folder via VB application

Hi Gang, can anyone tell me how to add a post item to a folder in my Outlook folder list from my VB application..  Thanks.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sub addFolder()

    Dim olookApp As Outlook.Application
    Dim olookSpace As Outlook.NameSpace
    Dim olookInbox As Outlook.MAPIFolder
    Dim olookFolder As Outlook.MAPIFolder
    Set olookApp = CreateObject("Outlook.Application")
    Set olookSpace = olookApp.GetNamespace("MAPI")
    'Must reference the folder we wish to create the new folder in.
    Set olookInbox = olookSpace.GetDefaultFolder(olFolderInbox).Parent
    'Use the Add method of the Folders collection of the MAPIFolder
    'object returned in the above statement.
    Set olookFolder = olookInbox.Folders.Add("MyNewFolder")
    Set olookFolder = Nothing
    Set olookInbox = Nothing
    Set olookSpace = Nothing
    Set olookApp = Nothing

End Sub

function to add a folder to outlook

DelboyAuthor Commented:
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
DelboyAuthor Commented:
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DelboyAuthor Commented:
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
Private Sub Command1_Click()
Dim outl As Outlook.Application
Dim outNmsp As Outlook.NameSpace
Dim outFolder As Outlook.MAPIFolder
Dim outMail As Outlook.MailItem
Dim outMovedMail As Outlook.MailItem
Set outl = New Outlook.Application
Set outNmsp = outl.GetNamespace("Mapi")
Set outFolder = outNmsp.GetDefaultFolder(olFolderInbox)
Set outMail = outFolder.Items.Add(olMailItem) 'add a newmail item
outMail.Subject = "Hello from Vb" 'subject
outMail.Body = "Yes, this is a new mail from vb!"
'uncomment this one if you want to make some tricks...
'outMail.SentOnBehalfOfName = "Would you like ah?!"
outMail.Save  'this will save it to the default for this kind of object, wich is not the inbox folder!
'now, move it where you want:
'you have to pass a folder to this method and...
' instantiate a new mailitem!
Set outMovedMail = outMail.Move(outFolder)
'now free memory
outMovedMail.Close olDiscard 'you already saved!
Set outMovedMail = Nothing
Set outMail = Nothing
Set outFolder = Nothing
Set outNmsp = Nothing
'depending on you wanting to keep alive outlook, you may skip the folowing
'but you will have to do this one!
Set outl = Nothing
End Sub
DelboyAuthor Commented:
Hi, sorry..  you are telling me how to send a mail from VB application.  I need to save a post item into a folder in my outlook folder list.
Look better: the code I posted do not send mail, but creates a new one and saves it to inbox folder. To save it somewhere else, simply
reference instead of "outFolder" the folder where you want to save it.
Set outMovedMail = outMail.Move(outFolder)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DelboyAuthor Commented:
My appologies..  I need glasses.  Thanks,  Derek.
>My appologies..  I need glasses.  Thanks,  Derek
...I am Cesare not Derek...(unless Derek is your name)
Have a nice day,
Cesare I.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.