![]() |
attachment delete problem
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 = " .Subject = "test" .BodyFormat = olFormatHTML .HTMLBody = "HTMLBODYSaludos cordiales. br/brBbrb AntoniobrN/b/br/BODY/HTML" .Display End With Else MsgBox "There is no active inspector." End If |
attachment delete problem
I have found some code that solves my needs:
While myattachments.Count 1 For Each attach In myattachments If Left(attach.Filename, 4) "Situ" Then attach.Delete Next attach Wend Apparently the attach.delete affects the attachment index. The iteration above with the while .count1 works. Is there a more direct way to do it? Thanks, Antonio "Antonio" wrote: 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 = " .Subject = "test" .BodyFormat = olFormatHTML .HTMLBody = "HTMLBODYSaludos cordiales. br/brBbrb AntoniobrN/b/br/BODY/HTML" .Display End With Else MsgBox "There is no active inspector." End If |
attachment delete problem
When removing things from a collection during a loop, you must count down in
reverse: For intX = Attachments.Count To 1 Step -1 Set myAttachment = Attachments.Item(intx) myAttachment.Delete Next -- Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Antonio" wrote: I have found some code that solves my needs: While myattachments.Count 1 For Each attach In myattachments If Left(attach.Filename, 4) "Situ" Then attach.Delete Next attach Wend Apparently the attach.delete affects the attachment index. The iteration above with the while .count1 works. Is there a more direct way to do it? Thanks, Antonio "Antonio" wrote: 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 = " .Subject = "test" .BodyFormat = olFormatHTML .HTMLBody = "HTMLBODYSaludos cordiales. br/brBbrb AntoniobrN/b/br/BODY/HTML" .Display End With Else MsgBox "There is no active inspector." End If |
attachment delete problem
The other way is with a countdown loop:
count = myattachments.Count For i = count to 1 Step -1 Set attach = myattachments.Item(i) attach.Delete Next -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Antonio" wrote in message ... I have found some code that solves my needs: While myattachments.Count 1 For Each attach In myattachments If Left(attach.Filename, 4) "Situ" Then attach.Delete Next attach Wend Apparently the attach.delete affects the attachment index. The iteration above with the while .count1 works. Is there a more direct way to do it? Thanks, Antonio "Antonio" wrote: 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 = " .Subject = "test" .BodyFormat = olFormatHTML .HTMLBody = "HTMLBODYSaludos cordiales. br/brBbrb AntoniobrN/b/br/BODY/HTML" .Display End With Else MsgBox "There is no active inspector." End If |
attachment delete problem
Thank you Eric and Sue for the solution.
I have used a slightly different one: For i = myattachments.Count To 1 Step -1 If Left(myattachments(i).Filename, 7) "Situaci" Then myattachments(i).Delete Next i "Sue Mosher [MVP-Outlook]" wrote: The other way is with a countdown loop: count = myattachments.Count For i = count to 1 Step -1 Set attach = myattachments.Item(i) attach.Delete Next -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Antonio" wrote in message ... I have found some code that solves my needs: While myattachments.Count 1 For Each attach In myattachments If Left(attach.Filename, 4) "Situ" Then attach.Delete Next attach Wend Apparently the attach.delete affects the attachment index. The iteration above with the while .count1 works. Is there a more direct way to do it? Thanks, Antonio "Antonio" wrote: 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 = " .Subject = "test" .BodyFormat = olFormatHTML .HTMLBody = "HTMLBODYSaludos cordiales. br/brBbrb AntoniobrN/b/br/BODY/HTML" .Display End With Else MsgBox "There is no active inspector." End If |
All times are GMT +1. The time now is 08:45 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com