To All
Can anyone help. I have some code (pasted below) which opens outlook from excel and creates a calendar invite. It works fine for about 70% of the time. For the remaining 30% I receive an error message stating the Microsoft Outlook has stopped working. When I click debug the line is highlighted as below. It seems that it may be happening when outlook is already open. I have tried to repeat the issue when outlook is closed when the code is triggered and cannot repeat the issue.
As always, any help would be appreciated
Here is the code
Can anyone help. I have some code (pasted below) which opens outlook from excel and creates a calendar invite. It works fine for about 70% of the time. For the remaining 30% I receive an error message stating the Microsoft Outlook has stopped working. When I click debug the line is highlighted as below. It seems that it may be happening when outlook is already open. I have tried to repeat the issue when outlook is closed when the code is triggered and cannot repeat the issue.
As always, any help would be appreciated
Here is the code
Code:
Sub Sample()
ActiveWorkbook.Save
Dim ol As Object
Dim Item As Object
Const olAppointmentItem = 1
'item As AppointmentItem
Set ol = CreateObject("Outlook.Application")
Set Item = ol.CreateItem(olAppointmentItem)
StartDate = [C11]
StartTime = [E11]
EndDate = [G11]
EndTime = [I11]
TimingofWork = [K11]
BuildingofWork = [C13]
Title = [I13]
DetailedDescriptionofWorks = [C15]
ImplementationPlan = [F17]
Whatmonitoring = [F19]
Backoutplan = [F21]
TestPlan = [F23]
PostImplementationVerification = [F25]
ImpacttoSytemOutputsandUsers = [C27]
Otherifapplicable = [C29]
CRNumber = [J31]
'Set Start Date
Item.Start = StartDate + TimeValue("00:00")
'Set End Date
Item.End = EndDate + TimeValue("00:30")
'appointment subject
Item.Subject = Title & " - " & BuildingofWork
'location description
Item.Location = BuildingofWork
'body message
Worksheets("Drop Down and Pastes").Range("C2:D22").Copy
Item.Display
[highlight #FCE94F]Item.GetInspector.WordEditor.Windows(1).Selection.PasteAndFormat wdPASTERTF[/highlight]
Item.Recipients.Add ("CR Notification Group")
'set the busy status
Item.BusyStatus = olFree
'reminder before start
Item.ReminderMinutesBeforeStart = 15
'reminder activated
Item.ReminderSet = True
'duh! save the thing!
Item.Display
'garbage collection - kind of...
Set ol = Nothing
Set Item = Nothing
'return true
makeReminder = True
End Sub