I am trying to use this block of code to save attachemnts from Outlook into a folder on my harddrive.
VB Code:
  1. Imports Microsoft.Office.Interop
  2. ''' <summary>
  3. ''' Saves Outlook attachment to the
  4. ''' client computer.
  5. ''' </summary>
  6. ''' <remarks></remarks>
  7. Public Class SlurpEmail
  8.     Private moApp As Outlook.Application
  9.  
  10.     Public Sub SlurpEmail()
  11.         Dim objOL As Outlook.Application
  12.         Dim objNS As Outlook.NameSpace
  13.         Dim objFolder As Outlook.Folders
  14.         Dim myItems As Outlook.Items
  15.         Dim x As Int16
  16.  
  17.         objOL = New Outlook.Application()
  18.         objNS = objOL.GetNamespace("MAPI")
  19.         Dim olfolder As Outlook.MAPIFolder
  20.         olfolder = objOL.GetNamespace("MAPI").PickFolder
  21.         myItems = olfolder.Items
  22.  
  23.         Dim filename As String
  24.         Dim Atmt As Outlook.Attachment
  25.         Dim Item As Object
  26.         For Each Atmt In Item.Attachments
  27.             filename = "C:\reports\" + Atmt.FileName
  28.             Atmt.SaveAsFile(filename)
  29.         Next Atmt
  30.     End Sub

It is erroring on this line For Each Atmt In Item.Attachments with this error Object variable or With block variable not set.