?
Solved

Adding a post to an Outlook Folder via VB application

Posted on 2003-03-18
9
Medium Priority
?
200 Views
Last Modified: 2010-05-01
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.
0
Comment
Question by:Delboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 

Expert Comment

by:yeeeooowww
ID: 8159628
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

0
 

Author Comment

by:Delboy
ID: 8159733
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
0
 

Author Comment

by:Delboy
ID: 8159795
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Delboy
ID: 8160148
Hi,  I dont want to add a folder,  I need to add a post item into an existing folder.

Thanks,  Derek.
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8160227
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
0
 

Author Comment

by:Delboy
ID: 8216697
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.
0
 
LVL 5

Accepted Solution

by:
Cimperiali earned 200 total points
ID: 8216778
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)
0
 

Author Comment

by:Delboy
ID: 8217916
My appologies..  I need glasses.  Thanks,  Derek.
0
 
LVL 5

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question