Outlook
A family of Microsoft email and calendar products.
3,427 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi guys,
I used the code which generated by OPENAI about activate Outlook's Autoreply on a certain date in VBA. Somehow it does not work due to some method or property does not support, but I don't know how to fix it.
Can anyone here help to check this?
The error happened in the below statement with the message: Type mismatch.
oPropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x661F001F", autoReplyMessage
Sub SetAutomaticReply()
Dim olApp As Object
Dim oNamespace As Object
Dim oStore As Object
Dim oPropertyAccessor As Object
Dim autoReplyMessage As String
Dim startDate As Date
Dim endDate As Date
' Set the start and end dates for the automatic reply
startDate = #5/10/2023#
endDate = #5/12/2023#
autoReplyMessage = "I am out of the office from " & Format(startDate, "dddd, mmmm d, yyyy") & " to " & Format(endDate, "dddd, mmmm d, yyyy") & ". I will respond to your email as soon as possible."
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set oNamespace = olApp.GetNamespace("MAPI")
Set oStore = oNamespace.DefaultStore
Set oPropertyAccessor = oStore.PropertyAccessor
' Enable automatic replies
oPropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x661D000B", True
' Set the automatic reply message
oPropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x661F001F", autoReplyMessage
End Sub
My Office version is Microsoft 365 for enterprise.