Hi All...
I have been working on a project that incorperates having to strip specific attachments from incomming E-Mails and save them to the Hard Drive. The code I created works.. But when I incorporate it into the main project that has Strict set to On.. But I get two error messages.. Setting Strict to Off isn't a current option..
1) Option Strict On disallows Late bindings.
2) Option Strict On disallows implicit Conversions from 'Outlook9.items' to 'Outlook9.ItemsClass'
Any help would be great.. Thanks..
Private Sub cleanup()
Dim myOlApp As Outlook.Application = New Outlook.Application()
Dim myOlExp As Outlook.Explorer
Dim myOLSel As Outlook.ItemsClass
Dim atmt As Object
Dim x As Integer
Dim lngCount As Long
Dim i As Long
Dim objAttach As Outlook.Attachments
Dim AttachmentsFolder As String
Dim strFileName As String
Dim atmtFileName As String
Dim msgAttachmentFiles As String
myOlExp = myOlApp.ActiveExplorer
myOLSel = myOlExp.CurrentFolder.Items
AttachmentsFolder = "C:\test\"
For x = 1 To myOLSel.Count
' Count the number of Attachments
lngCount = myOLSel.Item(x).attachments.count
' Handle the attachments
For Each atmt In myOLSel.Item(x).Attachments
' Get the attachment name and remove spaces, colons and underscores
If atmt.FileName.ToUpper Like "SPO*.PDF" Then
atmtFileName = atmt.FileName
' Save the attachment
atmt.SaveAsFile(AttachmentsFolder & atmtFileName)
End If
Next atmt
Next x
For x = 1 To myOLSel.Count
' Count the number of Attachments
lngCount = myOLSel.Item(x).attachments.count
' Handle the attachments
For Each atmt In myOLSel.Item(x).Attachments
If atmt.FileName.ToUpper Like "SPO*.PDF" Then
objAttach = myOLSel.Item(x).attachments
For i = lngCount To 1 Step -1
objAttach.Remove(i)
myOLSel.Item(x).Save()
lngCount = myOLSel.Item(x).attachments.count
Next
End If
Next
Next x
' Clear memory
myOlApp = Nothing
myOlExp = Nothing
myOLSel = Nothing
atmt = Nothing
objAttach = Nothing
End Sub
I have been working on a project that incorperates having to strip specific attachments from incomming E-Mails and save them to the Hard Drive. The code I created works.. But when I incorporate it into the main project that has Strict set to On.. But I get two error messages.. Setting Strict to Off isn't a current option..
1) Option Strict On disallows Late bindings.
2) Option Strict On disallows implicit Conversions from 'Outlook9.items' to 'Outlook9.ItemsClass'
Any help would be great.. Thanks..
Private Sub cleanup()
Dim myOlApp As Outlook.Application = New Outlook.Application()
Dim myOlExp As Outlook.Explorer
Dim myOLSel As Outlook.ItemsClass
Dim atmt As Object
Dim x As Integer
Dim lngCount As Long
Dim i As Long
Dim objAttach As Outlook.Attachments
Dim AttachmentsFolder As String
Dim strFileName As String
Dim atmtFileName As String
Dim msgAttachmentFiles As String
myOlExp = myOlApp.ActiveExplorer
myOLSel = myOlExp.CurrentFolder.Items
AttachmentsFolder = "C:\test\"
For x = 1 To myOLSel.Count
' Count the number of Attachments
lngCount = myOLSel.Item(x).attachments.count
' Handle the attachments
For Each atmt In myOLSel.Item(x).Attachments
' Get the attachment name and remove spaces, colons and underscores
If atmt.FileName.ToUpper Like "SPO*.PDF" Then
atmtFileName = atmt.FileName
' Save the attachment
atmt.SaveAsFile(AttachmentsFolder & atmtFileName)
End If
Next atmt
Next x
For x = 1 To myOLSel.Count
' Count the number of Attachments
lngCount = myOLSel.Item(x).attachments.count
' Handle the attachments
For Each atmt In myOLSel.Item(x).Attachments
If atmt.FileName.ToUpper Like "SPO*.PDF" Then
objAttach = myOLSel.Item(x).attachments
For i = lngCount To 1 Step -1
objAttach.Remove(i)
myOLSel.Item(x).Save()
lngCount = myOLSel.Item(x).attachments.count
Next
End If
Next
Next x
' Clear memory
myOlApp = Nothing
myOlExp = Nothing
myOLSel = Nothing
atmt = Nothing
objAttach = Nothing
End Sub