Morning all,
I have tried to set up code from other code obtained from the net. to save an xls attachment to a designated folder from a command button. my intention is to read all unread emails and save the attachments
My code boms out with error message Object required at line
For Each objAtt In itemAttachments
I am totally lost. Please help!
Here is the code:
Dim objOL As Outlook.Application
Dim itemAttachments As Outlook.Attachments
Dim strFile As String
Dim strFolder As String, item As Object
Dim strprogExt As String, arrext() As String, intpos As Integer
Dim objAtt As Attachment, i As Integer, strExt As String
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
Set objAtt = itemAttachments
' Get the Temp folder.
strFolder = GetTempDir()
If strFolder = "" Then
MsgBox "Could not get Temp folder", vbOKOnly
GoTo ExitSub
End If
strprogExt = "xls,exe"
' Check each selected item for attachments.
' If attachments exist, save them to the Temp
' folder and strip them from the item.
Set objAtt = itemAttachments
arrext = Split(strprogExt, ",")
For Each objAtt In itemAttachments
Stop
intpos = InStrRev(objAtt.FileName, ".")
If intpos > 0 Then
'check attachment ext
strExt = LCase(Mid(objAtt.FileName, intpos + 1))
For i = LBound(arrext) To LBound(arrext)
If strExt = Trim(arrext(i)) Then
Stop
item.Move strFolder
Exit For
End If
Next
Else
item.Move strFolder
End If
Next
ExitSub:
Set itemAttachments = Nothing
Set objOL = Nothing
End Sub
I have tried to set up code from other code obtained from the net. to save an xls attachment to a designated folder from a command button. my intention is to read all unread emails and save the attachments
My code boms out with error message Object required at line
For Each objAtt In itemAttachments
I am totally lost. Please help!
Here is the code:
Dim objOL As Outlook.Application
Dim itemAttachments As Outlook.Attachments
Dim strFile As String
Dim strFolder As String, item As Object
Dim strprogExt As String, arrext() As String, intpos As Integer
Dim objAtt As Attachment, i As Integer, strExt As String
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
Set objAtt = itemAttachments
' Get the Temp folder.
strFolder = GetTempDir()
If strFolder = "" Then
MsgBox "Could not get Temp folder", vbOKOnly
GoTo ExitSub
End If
strprogExt = "xls,exe"
' Check each selected item for attachments.
' If attachments exist, save them to the Temp
' folder and strip them from the item.
Set objAtt = itemAttachments
arrext = Split(strprogExt, ",")
For Each objAtt In itemAttachments
Stop
intpos = InStrRev(objAtt.FileName, ".")
If intpos > 0 Then
'check attachment ext
strExt = LCase(Mid(objAtt.FileName, intpos + 1))
For i = LBound(arrext) To LBound(arrext)
If strExt = Trim(arrext(i)) Then
Stop
item.Move strFolder
Exit For
End If
Next
Else
item.Move strFolder
End If
Next
ExitSub:
Set itemAttachments = Nothing
Set objOL = Nothing
End Sub