Masterkale
New Member
- Joined
- Mar 3, 2015
- Messages
- 4
Hello people i have a code working that will shoot appointments into my default calendar and delete the old ones. But now i would like to shoot them from my pc into my collegues their pc. I tried to search on GetSharedDefaultFolder but i cant solve this. (was getting runtime errors 438 etc.) Can somebody help me?
Code:
Public Sub CommandButton21_Click()
' delete all orders with #(^)#
deleteOutlookAppt
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")
Worksheets("Uitvoerder").Select
' 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, 15).Value
myApt.Location = Cells(r, 17).Value
myApt.Start = Cells(r, 18).Value
myApt.Duration = Cells(r, 6).Value
myApt.Categories = Cells(r, 10).Value
' If Busy Status is not specified, default to 2 (Busy)
If Trim(Cells(r, 8).Value) = "" Then
myApt.BusyStatus = 2
Else
myApt.BusyStatus = Cells(r, 8).Value
End If
If Cells(r, 7).Value > 0 Then
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = Cells(r, 7).Value
Else
myApt.ReminderSet = False
End If
myApt.Body = Cells(r, 13).Value
myApt.Save
r = r + 1
Loop
MsgBox "De orders zijn naar outlook gekopieerd."
End Sub
Sub deleteOutlookAppt()
Dim olApp As Object 'Outlook.Application
Dim olNS As Object 'Outlook.Namespace
Dim olAptItemFolder As Object 'Outlook.Folder
Dim olAptItem As Object 'Outlook.AppointmentItem
Dim i As Long
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.Session
Set olAptItemFolder = olNS.GetDefaultFolder(9) '9=olFolderCalendar constant
For i = olAptItemFolder.Items.Count To 1 Step -1
Set olAptItem = olAptItemFolder.Items(i)
If olAptItem.Subject Like "*(^)*" Then
olAptItem.Delete
End If
Next i
Set olAptItem = Nothing
Set olAptItemFolder = Nothing
Set olApp = Nothing
End Sub