Masterkale
New Member
- Joined
- Mar 3, 2015
- Messages
- 4
Hello i am trying to build an orderlist with some planned maintenance jobs. When the list is updated i want them to copy them to outlook calendar so the guys can see what kind of work they have to do.
But .... The start date of the orders are sometimes changed. So when i shoot them into outlook they will duplicate but on a different date. Now i got 2 buttons 1: to shoot the orders into outlook and button2: To delete duplicate orders on other startdates, but it will delete the good planned order and keeps the wrong one (older one).
I am a total noob with VBA so please tell me step by step what to do to solve this.
thank you
But .... The start date of the orders are sometimes changed. So when i shoot them into outlook they will duplicate but on a different date. Now i got 2 buttons 1: to shoot the orders into outlook and button2: To delete duplicate orders on other startdates, but it will delete the good planned order and keeps the wrong one (older one).
I am a total noob with VBA so please tell me step by step what to do to solve this.
thank you
Code:
Private Sub CommandButton21_Click()
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myApt = myOutlook.createitem(1)
' Set the appointment properties
myApt.Subject = Cells(r, 2).Value
myApt.Location = Cells(r, 3).Value
myApt.Start = Cells(r, 4).Value
myApt.Duration = Cells(r, 5).Value
' If Busy Status is not specified, default to 2 (Busy)
If Trim(Cells(r, 7).Value) = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Cells(r, 7).Value
End If
If Cells(r, 6).Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Cells(r, 6).Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Cells(r, 1).Value
myApt.Save
r = r + 1
Loop
MsgBox "De orders zijn naar outlook gekopieerd."
End Sub
Private Sub CommandButton22_Click()
' Delete duplicate appointments
Const olFolderCalendar = 9
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
Set myItems = myFolder.Items
'Sort the calendar database
Dim strTri
strTri = ""
strTri = strTri & "[Start]"
strTri = strTri & "[End]"
strTri = strTri & "[Subject]"
strTri = strTri & "[Body]"
strTri = strTri & "[AllDayEvent]"
strTri = strTri & "[Sensitivity]"
myItems.Sort strTri
'Delete successive equal appointments
Dim lastStr, Str, nbrDelete
lastStr = ""
nbrDelete = 0
For Each Item In myItems
Str = ""
Str = Str & vbCrLf & Item.Subject
Str = Str & vbCrLf & Item.Body
Str = Str & vbCrLf & Item.AllDayEvent
Str = Str & vbCrLf & Item.Sensitivity
Str = Replace(Str, vbCrLf & vbCrLf, vbCrLf)
Str = Replace(Str, vbCrLf & vbCrLf, vbCrLf)
Str = Replace(Str, vbCrLf & vbCrLf, vbCrLf)
Str = Replace(Str, vbCrLf & vbCrLf, vbCrLf)
Str = Replace(Str, vbCrLf & vbCrLf, vbCrLf)
If Str = lastStr Then
Item.Delete
nbrDelete = nbrDelete + 1
End If
lastStr = Str
Next
MsgBox "Dubbele orders gewist. : " & nbrDelete
End Sub