PDA

View Full Version : Out of Office message and calendar event



jumpjack
06-10-2010, 02:50 AM
Every time I activate Out Of Office message, when I get back to my office I forgot disabling it, as I leave Outlook running!
How could I avoid this?
Does it exist a macro which, upon pressing a button, both enables OutOfOffice and create an alarm which is triggered when OOO message is supposed to expire? Or should I write it from scratch? I can't believe I'm the only one with this problem! :think:

gcomyn
08-17-2010, 02:25 PM
Here is some code that is supposed to do what you want, but I can't get it to work. I'm using Outlook 2007, and I have the CDO 1.21 loaded, but it won't get past the Set ms = CreateObject("MAPI.Session") line in the "SetOutOfOffice" function.


Sub VacationSetup()

On Error GoTo ErrorHandler

Dim StartDate As Date
Dim EndDate As Date
Dim i As Long

' set up out of office msg
Call SetOutOfOffice

' ask for vacation days
StartDate = CDate(InputBox("Enter the first day of your vacation, " & _
"in the format: mm/dd/yyyy"))
EndDate = CDate(InputBox("Enter the last day of your vacation, " & _
"in the format: mm/dd/yyyy"))

' set up all day "appointments" for each weekday
For i = StartDate To EndDate
If IsWeekday(i) Then
Call SetAllDayAppt(i)
End If
Next i

ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.number & " - " & Err.Description
Resume ProgramExit
End Sub

Function SetOutOfOffice(Optional OOOStatus As Boolean = True, _
Optional OOOText As String = "I'm currently out of the office.")

Dim ms As Object
' requires CDO 1.21
Set ms = CreateObject("MAPI.Session")

' set out of office status
ms.OutOfOffice = OOOStatus

' if we are out, then set/change message text
If OOOStatus Then
ms.OutOfOfficeText = OOOText
End If

End Function

Function SetAllDayAppt(vacationDate As Long)

Dim olApp As Outlook.Application
Dim appt As Outlook.AppointmentItem

Set olApp = GetOutlookApp
Set appt = olApp.CreateItem(olAppointmentItem)

With appt
.Start = vacationDate
.AllDayEvent = True
.Subject = "On Vacation"
.ReminderSet = False
.BusyStatus = olOutOfOffice
.Save
End With

End Function

Function GetOutlookApp() As Outlook.Application
Set GetOutlookApp = Outlook.Application
End Function

Function IsWeekday(vacationDate As Long) As Boolean
' returns True if given date is Saturday or Sunday
IsWeekday = (Weekday(vacationDate, vbMonday) < 6)
End Function


Hope it helps.




GComyn
:sleuth:

gcomyn
08-17-2010, 02:56 PM
after looking some more, I figured it out. This is the change.


Function SetOutOfOffice(Optional OOOStatus As Boolean = True, _
Optional OOOText As String = "I'm currently out of the office.")

Dim ms As MAPI.Session
' requires CDO 1.21
Set ms = CreateObject("MAPI.Session")
ms.Logon "", "", False, False 'piggy-back logon
' set out of office status
ms.OutOfOffice = OOOStatus

' if we are out, then set/change message text
If OOOStatus Then
ms.OutOfOfficeText = OOOText
End If

End Function

This is set the Out Of Office at the time you run it, and set the text for the out of office reply, then put 'On Vacation' on the dates that you set.

GComyn
:sleuth:

jumpjack
08-17-2010, 11:50 PM
Thanks for your effort. Although this is not what I asked for, I think I can use it to figure out how to write down the script I need: it must warn me about OOO being currently enabled, hence it must set a remainder which pops up once I get back to my PC after holydays (which, BTW, already happened... :banghead:)

dadoo
05-09-2012, 12:57 AM
Here is a NO link, just a pointer, to some code to turn On and Off Out of Office, using the Outlook event when it starts or shuts down.
I do not understand the sub doing the actual work (using some URL to microsoft.com).

I found it in Experts Exchange forum under the title Automating Out of Office in Outlook.

Dadoo René

dadoo
05-09-2012, 01:31 AM
To turn off the OOO notification when Outlook is running, you can use one of the Outlook triggered events (there are many).
To find the list, I found the following reference:

Mastering VBA for Microsoft Office 2007 - Google Books Result
isbn=0470279591...Richard Mansfield - 2008 - Computers - 888 pages

And Google provides the scanned source.
Dadoo René (dadoo.ch)

jumpjack
05-09-2012, 01:31 AM
Here is a NO link, just a pointer, to some code to turn On and Off Out of Office, using the Outlook event when it starts or shuts down.
I do not understand the sub doing the actual work (using some URL to microsoft.com).

I found it in Experts Exchange forum under the title Automating Out of Office in Outlook.

Dadoo René
Sub OutOfOffice(bolState As Boolean)
Const PR_OOF_STATE = "http://schemas.microsoft.com/mapi/proptag/0x661D000B"
Dim olkIS As Outlook.Store, olkPA As Outlook.PropertyAccessor
For Each olkIS In Session.Stores
If olkIS.ExchangeStoreType = olPrimaryExchangeMailbox Then
Set olkPA = olkIS.PropertyAccessor
olkPA.SetProperty PR_OOF_STATE, bolState
End If
Next
Set olkIS = Nothing
Set olkPA = Nothing
End Sub

Declaration is not working for me:
Dim olkIS As Outlook.Store, olkPA As Outlook.PropertyAccessor

.Store and .PropertyAccessor appear as not existing. (OL 2003 SP3).

JP2112
05-23-2012, 06:01 PM
Those properties were added in Outlook 2007. In Outlook 2003, you will need to use CDO to set the Out Of Office status and text as outlined in the previous replies in this thread.

And for the record, even though I might get flamed for this, the code in this thread was written by me and comes from this article:

Going on Vacation with Outlook (http://www.jpsoftwaretech.com/outlook-vba/going-on-vacation-with-outlook/)

Apologies to the forum owners but I have seen this code posted in several forums with no mention of source.

jumpjack
05-24-2012, 12:09 AM
Apologies to the forum owners but I have seen this code posted in several forums with no mention of source.
A link WAS present in the post... but it was removed by moderators, hence I had to just paste your code:


Here is a NO link, just a pointer, to some code to
("NO link" replaced the link!)

JP2112
05-24-2012, 05:04 AM
Understood, thank you for clarifying.

kuwlij
02-01-2013, 03:17 AM
Every time I activate Out Of Office message, when I get back to my office I forgot disabling it, as I leave Outlook running!
How could I avoid this?
Does it exist a macro which, upon pressing a button, both enables OutOfOffice and create an alarm which is triggered when OOO message is supposed to expire? Or should I write it from scratch? I can't believe I'm the only one with this problem! :think:

Hi there,
I subscribed just to answer this! lol

I too have been googling this and came across this article. I don't know if you have solved this issue. a way to go about this, i thought was to set start and end dates to the OOO using start and end dates of an OOO appointment (appointment reminder triggers the event that sets OOO using the code you posted later from expert exchange). Unfortunately, i didn't find how to get to the OOO parameters.

As a practical work around, I made a basic userform that pops up when out of office is set, with a button that triggers the disabling of the out of office. (this works for me as i need to leave my work computer running 24/7also)

Private Sub Application_Reminder(ByVal Item As Object)

If Item.BusyStatus = olOutOfOffice Then
OutOfOffice True
UserFormOOO.Show
End If
End Sub

In the userform, i have a label called Labeldisable with an event tied to in on click
Private Sub Labeldisable_Click()
OutOfOffice False
UserFormOOO.Hide
End Sub


hope this helps :)