Link to home
Start Free TrialLog in
Avatar of Delboy
DelboyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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.


Derek.
Avatar of yeeeooowww
yeeeooowww

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

Avatar of Delboy

ASKER

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

Thanks,  Derek.
Avatar of Delboy

ASKER

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

Thanks,  Derek.
Avatar of Delboy

ASKER

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...
'...to 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
outl.Quit
'but you will have to do this one!
Set outl = Nothing
End Sub
Avatar of Delboy

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Cimperiali
Cimperiali
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Delboy

ASKER

My appologies..  I need glasses.  Thanks,  Derek.
LOL:
>My appologies..  I need glasses.  Thanks,  Derek
...I am Cesare not Derek...(unless Derek is your name)
;-)
Have a nice day,
Cesare I.