It is working now.
Here is my complete code
I am getting a security warning from outlook "a program is trying to
access email address from outlook" how to get rid of that message?
Also, instead of "Unread items" from the inbox I would like to use
selected(highlighted) items from the inbox any way to do this
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Create Outlook Application.
Dim objApp As Outlook.Application = New Outlook.Application
'Get Mapi NameSpace
Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI")
objNS.Logon("GA\Cshah", Missing.Value, False, True)
' Get Messages collection of Inbox.
Dim objInbox As Outlook.MAPIFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim objItems As Outlook.Items = objInbox.Items
' Get unread e-mail messages. (Collection)
objItems = objItems.Restrict("[UnRead] = true")
' objItems = objItems.Restrict(
'Mail Item
Dim oMsg As Outlook.MailItem
For Each oMsg In objItems
Dim objAttachment As Outlook.Attachment
For Each objAttachment In oMsg.Attachments
Dim filename As String
filename = "C:\Temp\" + objAttachment.FileName
objAttachment.SaveAsFile(filename)
Next objAttachment
Next
Label1.Text = "Attachments are saved"
End Sub