woodan1
asked on
How do I delete appointments by category - macro/vb
Anyone have a macro to delete the appointment entries by a preset category with code:
Heres the manual way:
View
Current View
By Category
Select the Category: SQLData
Delete
Heres the manual way:
View
Current View
By Category
Select the Category: SQLData
Delete
ASKER
I pasted this code into vb in outlook and it states that macros have been disabled. How can I run this code??
you can lower yourmacro security settings under tools| macros | security to something else then high
maybe you have to restart outlook for it to take effect but i didn't think so
if you lower it it will be able to run
maybe you have to restart outlook for it to take effect but i didn't think so
if you lower it it will be able to run
ASKER
I had to restart outlook.
It works but I am getting an error...array index out of bounds
Sub DeleteSpecifiedAppointment s(strCat As String)
Dim objNS As Outlook.NameSpace
Dim objApptFolder As Outlook.MAPIFolder, objAppt As Outlook.AppointmentItem
Dim objItems As Outlook.Items, intX As Integer
Set objNS = Application.GetNamespace(" MAPI")
Set objApptFolder = objNS.GetDefaultFolder(olF olderCalen dar)
Set objItems = objApptFolder.Items
For intX = 1 To objItems.Count
Set objAppt = objItems.Item(intX) <<<<<after it's deleted then it errors here.
If objAppt.Categories = strCat Then
objAppt.Delete
End If
Next
Set objNS = Nothing
Set objApptFolder = Nothing
Set objItems = Nothing
End Sub
It works but I am getting an error...array index out of bounds
Sub DeleteSpecifiedAppointment
Dim objNS As Outlook.NameSpace
Dim objApptFolder As Outlook.MAPIFolder, objAppt As Outlook.AppointmentItem
Dim objItems As Outlook.Items, intX As Integer
Set objNS = Application.GetNamespace("
Set objApptFolder = objNS.GetDefaultFolder(olF
Set objItems = objApptFolder.Items
For intX = 1 To objItems.Count
Set objAppt = objItems.Item(intX) <<<<<after it's deleted then it errors here.
If objAppt.Categories = strCat Then
objAppt.Delete
End If
Next
Set objNS = Nothing
Set objApptFolder = Nothing
Set objItems = Nothing
End Sub
ASKER
my objItems.Count =76, but the intX=77 when it errors
try this line instead of the original from the looks of it has to do with going one item to far in the loop
For intX = 1 To objItems.Count -1
For intX = 1 To objItems.Count -1
ASKER
If I rerun again after they're all gone, it doesn't error. It only errors when it is deleting. Hummm.
To test I reimported the appointments, reran the macro and it errors. I rerun the delete macro again and it is fine. Hummmm.
To test I reimported the appointments, reran the macro and it errors. I rerun the delete macro again and it is fine. Hummmm.
ASKER
I'm a little behind your notes, but no that didn't work.
Hi Brian,
> If objAppt.Categories = "SQLData" Then
That will work just fine, unless an appointment has more than one category associated with it, in which case the appointment's
Categories property is a delimited string of all the associated Categories...
Regards,
Patrick
> If objAppt.Categories = "SQLData" Then
That will work just fine, unless an appointment has more than one category associated with it, in which case the appointment's
Categories property is a delimited string of all the associated Categories...
Regards,
Patrick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bruintje, that did it.
ASKER
I am importing data that I am setting as a particular category (it's users proposed vacation days) from a db. This function will allow me to delete them before repopulating them. That way they never get out of sync - unless someone messes with the category. If they do then it's their problem. The users most likely will not mess with the category - a good bet anyway.
Thanks.
Thanks.
glad it worked :)
you could use something along the lines of this macro by Eric Legault
source: http://groups.google.com/group/microsoft.public.outlook.program_vba/msg/45980946ff0ba774
--------------
Sub DeleteSpecifiedAppointment
Dim objNS As Outlook.NameSpace
Dim objApptFolder As Outlook.MAPIFolder, objAppt As Outlook.AppointmentItem
Dim objItems As Outlook.Items, intX As Integer
Set objNS = Application.GetNamespace("
Set objApptFolder = objNS.GetDefaultFolder(olF
Set objItems = objApptFolder.Items
For intX = 1 To objItems.Count
Set objAppt = objItems.Item(intX)
If objAppt.Categories = "SQLData" Then
objAppt.Delete
End If
Next
End Sub
--------------
hope this helps a bit
bruintje