Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Adding a post to an Outlook Folder via VB application

Posted on 2003-03-18
9
Medium Priority
?
202 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
  • 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
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!

 

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

Independent Software Vendors: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

578 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