JeenLeen
2014-05-28, 03:40 PM
I read somewhere about someone writing a VBA script that created a button in an Excel ribbon, which when clicked would e-mail someone asking them to please call. They used this to be able to answer the phone and pretend to be busy when an annoying co-worker would stop by.
I created the 'e-mail to call me' code, but I'm having trouble modifying the ribbon and was hoping y'all could point me in the right direction.
My current idea is something like this (the Sub AvoidAnnoyance works as-is):
Option Explicit
'note: if code does not work, you may need to go to Tools -- References and select Microsoft Outlook
Private Sub Project_Open()
Call AddButton
End Sub
Sub AddButton()
'code to add a button to the Home ribbon which calls the AvoidAnnoyance() sub
End Sub
'This code sends a meeting request to the selected individual.
Sub AvoidAnnoyance()
Dim outobj As Outlook.Application, outappt As Outlook.AppointmentItem
Dim mtgTime As Date
mtgTime = Now()
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.MeetingStatus = olMeeting
.Subject = " Call 555-5555"
.Location = "MyName Call"
.Body = "Give me a call and help me out here: 555-5555"
.Start = mtgTime
.Duration = 1 'one minute so not impact calendar negatively
.ReminderSet = True
.ReminderMInutesBeforeStart = 1
.Recipients.Add ("[email protected]")
'.Recipients.Add ("[email protected]") ' you can add more of these if you want
.Send
.save
End With
End Sub
Also, I've noticed that in Excel's VBA, I need to go to References and select the MS Outlook objects in order to use code that messes with Outlook. Is there any way, such as in the Open_Project code, to check if these settings are as I need them and set them programmatically instead of manually? Would that let the code run? (I can see yes, because by the time it gets to the Outlook objects, the settings are such that it knows what they are. But I could also see no, if the code checks everything before it changes the settings.)
I created the 'e-mail to call me' code, but I'm having trouble modifying the ribbon and was hoping y'all could point me in the right direction.
My current idea is something like this (the Sub AvoidAnnoyance works as-is):
Option Explicit
'note: if code does not work, you may need to go to Tools -- References and select Microsoft Outlook
Private Sub Project_Open()
Call AddButton
End Sub
Sub AddButton()
'code to add a button to the Home ribbon which calls the AvoidAnnoyance() sub
End Sub
'This code sends a meeting request to the selected individual.
Sub AvoidAnnoyance()
Dim outobj As Outlook.Application, outappt As Outlook.AppointmentItem
Dim mtgTime As Date
mtgTime = Now()
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.MeetingStatus = olMeeting
.Subject = " Call 555-5555"
.Location = "MyName Call"
.Body = "Give me a call and help me out here: 555-5555"
.Start = mtgTime
.Duration = 1 'one minute so not impact calendar negatively
.ReminderSet = True
.ReminderMInutesBeforeStart = 1
.Recipients.Add ("[email protected]")
'.Recipients.Add ("[email protected]") ' you can add more of these if you want
.Send
.save
End With
End Sub
Also, I've noticed that in Excel's VBA, I need to go to References and select the MS Outlook objects in order to use code that messes with Outlook. Is there any way, such as in the Open_Project code, to check if these settings are as I need them and set them programmatically instead of manually? Would that let the code run? (I can see yes, because by the time it gets to the Outlook objects, the settings are such that it knows what they are. But I could also see no, if the code checks everything before it changes the settings.)