Sub ConvertMeetingsToAppts()
Dim strWindowType As String
Dim sel As Outlook.Selection
Dim itm As Object
strWindowType = TypeName(Application.ActiveWindow)
Select Case strWindowType
Case "Explorer"
Set sel = Application.ActiveExplorer.Selection
If sel.count > 0 Then
For Each itm In sel
If itm.Class = olAppointment Then
If itm.MeetingStatus <> olNonMeeting Then
Call ConvertMeetingToAppt(itm)
End If
End If
Next
End If
Case "Inspector"
Set itm = Application.ActiveInspector.CurrentItem
If itm.Class = olAppointment Then
If itm.MeetingStatus <> olNonMeeting Then
Call ConvertMeetingToAppt(itm)
End If
End If
End Select
Set itm = Nothing
Set sel = Nothing
End Sub
Sub ConvertMeetingToAppt(myMeeting As Outlook.AppointmentItem)
With myMeeting
' remove all recipients
Do Until .Recipients.count = 0
.Recipients.Remove 1
Loop
' reset meeting status
.MeetingStatus = olNonMeeting
.Save
End With
End Sub
Sub ImportAppointments()
Dim excApp As Object, _
excBook As Object, _
excSheet As EObject, _
olkFolder As Outlook.Folder, _
olkAppointment As Outlook.AppointmentItem, _
intRow As Integer, _
datTemp As Date
Set excApp = CreateObject("Excel.Application")
'Change the path and file name on the next line'
Set excBook = excApp.Workbooks.Open("C:\eeTesting\2009-Faithworks-Import.xls")
Set excSheet = excBook.Worksheets("Sheet1")
excApp.Visible = True
intRow = 2
Do While excSheet.Cells(intRow, 1) <> ""
Set olkAppointment = Application.CreateItem(olAppointmentItem)
With olkAppointment
.Subject = excSheet.Cells(intRow, "A")
.Start = CDate(excSheet.Cells(intRow, "B") & " " & CDate(excSheet.Cells(intRow, "C")))
.End = excSheet.Cells(intRow, "D") & " " & CDate(excSheet.Cells(intRow, "E"))
.AllDayEvent = excSheet.Cells(intRow, "F")
.ReminderSet = excSheet.Cells(intRow, "G")
datTemp = CDate(excSheet.Cells(intRow, "H") & " " & CDate(excSheet.Cells(intRow, "I")))
.ReminderMinutesBeforeStart = DateDiff("n", datTemp, .Start)
.Body = excSheet.Cells(intRow, "J")
.Location = excSheet.Cells(intRow, "K")
.Importance = IIf(excSheet.Cells(intRow, "L") = "High", olImportanceHigh, olImportanceNormal)
.Sensitivity = IIf(LCase(excSheet.Cells(intRow, "M")) = "true", olPrivate, olNormal)
.Categories = excSheet.Cells(intRow, "O")
.Display
End With
intRow = intRow + 1
Loop
Set olkAppointment = Nothing
Set excSheet = Nothing
excBook.Close False
Set excBook = Nothing
excApp.Quit
Set excApp = Nothing
MsgBox "Finished"
End Sub
1. The actual work is done by the ConvertMeetingToAppt subroutine, which takes an Outlook.AppointmentItem as its sole argument.
2. The ConvertMeetingsToAppts demonstrates how to construct a macro that can run against both an Explorer (folder) window or an Inspector (item) window by checking the ActiveWindow property.
3. Calls to the Recipients collection will trigger a security prompt in Outlook VBA code in versions earlier than Outlook 2003 and 2007.
4. Put the code in any Outlook VBA code module.
5. If you might want to run in a loop than you can use a countdown loop.
6. Nothing in this code is version-specific. You can use it in the Outlook 2007
Open in new window