A
Antonio
the following code is called from whithin an Excel VBA module.
It works fine but it leaves an attachment that should not be left, its name
does not start by "Situ".
The attachment that is left is a workbook .xls that I click on and then run
the excel macro.
How can I get rid of this unwanted attachment?
When I loop through it in the For each attach it does not go through it, as
if it did not exist.
Dim myolApp As Outlook.Application
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myattachments As Outlook.Attachments
Dim attach As Outlook.Attachment
Set myolApp = CreateObject("Outlook.Application")
Set myinspector = myolApp.ActiveInspector
If Not TypeName(myinspector) = "Nothing" Then
Set myItem = myinspector.CurrentItem.Forward
Set myattachments = myItem.Attachments
For Each attach In myattachments
If Left(attach.Filename, 4) <> "Situ" Then attach.Delete
Next attach
With myItem
.To = "(e-mail address removed)"
.Subject = "test"
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>Saludos cordiales. <br></br><B><br><b>
Antonio<br>N</b></br></BODY></HTML>"
.Display
End With
Else
MsgBox "There is no active inspector."
End If
It works fine but it leaves an attachment that should not be left, its name
does not start by "Situ".
The attachment that is left is a workbook .xls that I click on and then run
the excel macro.
How can I get rid of this unwanted attachment?
When I loop through it in the For each attach it does not go through it, as
if it did not exist.
Dim myolApp As Outlook.Application
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myattachments As Outlook.Attachments
Dim attach As Outlook.Attachment
Set myolApp = CreateObject("Outlook.Application")
Set myinspector = myolApp.ActiveInspector
If Not TypeName(myinspector) = "Nothing" Then
Set myItem = myinspector.CurrentItem.Forward
Set myattachments = myItem.Attachments
For Each attach In myattachments
If Left(attach.Filename, 4) <> "Situ" Then attach.Delete
Next attach
With myItem
.To = "(e-mail address removed)"
.Subject = "test"
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><BODY>Saludos cordiales. <br></br><B><br><b>
Antonio<br>N</b></br></BODY></HTML>"
.Display
End With
Else
MsgBox "There is no active inspector."
End If