mrnoobexcel
New Member
- Joined
- Nov 20, 2017
- Messages
- 3
Hello All,
I found a macro that creates an outlook appointment, this code works perfectly inside a module. I then copied this code and pasted it inside a command button in a userform, but when I run the form and click on the button, nothing happens as if there's no code inside the button. I've searched the web for an answer to no avail. Can someone help? Also, the working module is a public sub just in case this info is necessary. Here's the code inside the command button:
I found a macro that creates an outlook appointment, this code works perfectly inside a module. I then copied this code and pasted it inside a command button in a userform, but when I run the form and click on the button, nothing happens as if there's no code inside the button. I've searched the web for an answer to no avail. Can someone help? Also, the working module is a public sub just in case this info is necessary. Here's the code inside the command button:
Code:
Public Sub CreateAppointment()
Dim oApp As Outlook.Application
Dim oNameSpace As NameSpace
Dim oItem As AppointmentItem
On Error Resume Next
' check if Outlook is running
Set oApp = GetObject("Outlook.Application")
If Err <> 0 Then
'if not running, start it
Set oApp = CreateObject("Outlook.Application")
End If
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oItem = oApp.CreateItem(olAppointmentItem)
With oItem
.subject = "This is the subject"
.Start = "31/05/2011 11:45"
.AllDayEvent = True
.Importance = olImportanceNormal
.Categories = "Green Category"
.ReminderSet = True
.ReminderMinutesBeforeStart = "15"
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.wav"
Select Case 1 ' do you want to display the entry first or save it immediately?
Case 1
.Display
Case 2
.Save
End Select
End With
Set oApp = Nothing
Set oNameSpace = Nothing
Set oItem = Nothing
End Sub