Solved

Deleting Only Attachments of all Outlook Calender Enteries.

Posted on 2009-07-02
2
145 Views
Last Modified: 2012-05-07
Help get this code working.

I ran the code found in: http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_23710781.html?sfQueryTermInfo=1+attach+delet+outlook

When I enter the date in various formats I always get Run-time error 'Cannot save the attachment.'

Debug focus on:
                            .attachments.Item(intCount).SaveAsFile myOrt & _
                            .attachments.Item(intCount).DisplayName
Sub DeleteCalendarAttachments()
    Dim strEnd As String, _
        myOrt As String, _
        olkCalendar As Outlook.MAPIFolder, _
        olkAppointment As Outlook.AppointmentItem, _
        intCount As Integer, _
        intMsgsInDateRange As Integer, _
        intItemsWithAttachments As Integer, _
        intAttachmentsRemoved As Integer
    strEnd = Format(InputBox("Enter the end date (DD/MM/YYYY:)"), "ddddd") 'user input last date to remove appointments
    If Not IsDate(strEnd) Then
        MsgBox "No date entered.  Run again and enter a date.", vbCritical + vbOKOnly, "DeleteCalnedarAttachments - Error"
    Else
        myOrt = "H:\Attachments\"
        Set olkCalendar = Application.ActiveExplorer.CurrentFolder
        For Each olkAppointment In olkCalendar.Items
            With olkAppointment
                'Change the dates on the next line as desired
                 If .Start <= CDate(strEnd) Then
                    intMsgsInDateRange = intMsgsInDateRange + 1
                    If .attachments.Count > 0 Then
                        intItemsWithAttachments = intItemsWithAttachments + 1
                        For intCount = .attachments.Count To 1 Step -1
                            .attachments.Item(intCount).SaveAsFile myOrt & _
                            .attachments.Item(intCount).DisplayName
                            .attachments.Item(intCount).Delete
                            intAttachmentsRemoved = intAttachmentsRemoved + 1
                        Next
                        .Save
                    End If
                End If
            End With
        Next
        If intMsgsInDateRange = 0 Then
            MsgBox "All done.  There were no messages in the date range specified.", vbInformation + vbOKOnly, "Delete Calendar Attachments Macro"
        Else
            MsgBox "All done!" & vbCrLf & "We removed " & intAttachmentsRemoved & " attachments from " & _
                intItemsWithAttachments & " appointments.", vbInformation + vbOKOnly, "Delete Calendar Attachments Macro"
        End If
    End If
    Set olkAppointment = Nothing
    Set olkCalendar = Nothing
End Sub

Open in new window

0
Comment
Question by:Dooglave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
ioane earned 500 total points
ID: 24769713
Do you have an H: drive?
0
 
LVL 6

Author Comment

by:Dooglave
ID: 24795663
lol, no.  I bet that's it.   Thanks I'll get back to you when I have time to do this again.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question