Reputation: 31
I am using this code in Outlook VBA to check and set automatic Reply Feature Status. When I activate the feature in outlook manually and check the status via VBA, then i am getting the expected value everytime.
But when i set the value via VBA, i can check also via VBA that it was set to True for example but the function looks not activated in outlook. I tried to send an e-mail from another account to see if i receive an automatic reply, but i got no automatic reply.
Sub CheckStatus()
MsgBox Check_Out_Of_Office()
End Sub
Sub ActivateStatus()
OutOfOffice True
End Sub
Function Check_Out_Of_Office() As Boolean
'Checks to see if out of office is already enabled
On Error GoTo eh
Dim oNS As Outlook.NameSpace
Dim oStores As Outlook.Stores
Dim oStr As Outlook.Store
Dim oPrp As Outlook.PropertyAccessor
Set oNS = Outlook.GetNamespace("MAPI")
Set oStores = oNS.Stores
For Each oStr In oStores
If oStr.ExchangeStoreType = olPrimaryExchangeMailbox Then
Set oPrp = oStr.PropertyAccessor
Check_Out_Of_Office = oPrp.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B")
End If
Next
Exit Function
eh:
MsgBox "The following error occurred: " & Err.Description
End Function
Sub OutOfOffice(bolState As Boolean)
'Calling this with a state of True enables out of office and calling it with a state of False disables out of office
On Error GoTo eh
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
Exit Sub
eh:
MsgBox "The following error occurred: " & Err.Description
End Sub
I found this code under: https://4sysops.com/archives/automate-out-of-office-messages-in-outlook-with-visual-basic-for-applications-vba/
I am having exchange account using Microsoft 365
I don't want to install any external libs like redemption which are not included in Outlook.
Upvotes: 1
Views: 60
Reputation: 66276
While PR_OOF_STATE
can be used to read the OOF state, setting it requires SetUserOofSettings
EWS method. See https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/hh532556(v=exchg.80)
Upvotes: 0