I am trying to use this block of code to save attachemnts from Outlook into a folder on my harddrive.
VB Code:
Imports Microsoft.Office.Interop ''' <summary> ''' Saves Outlook attachment to the ''' client computer. ''' </summary> ''' <remarks></remarks> Public Class SlurpEmail Private moApp As Outlook.Application Public Sub SlurpEmail() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.Folders Dim myItems As Outlook.Items Dim x As Int16 objOL = New Outlook.Application() objNS = objOL.GetNamespace("MAPI") Dim olfolder As Outlook.MAPIFolder olfolder = objOL.GetNamespace("MAPI").PickFolder myItems = olfolder.Items Dim filename As String Dim Atmt As Outlook.Attachment Dim Item As Object For Each Atmt In Item.Attachments filename = "C:\reports\" + Atmt.FileName Atmt.SaveAsFile(filename) Next Atmt 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.


Reply With Quote
