Not able to update email body in Meeting Request

493 Views Asked by At

I am not able to create a meeting request. I get an error on .HTMLbody line. The error which I receive is "Run time error '438' Object does not support this property or method" . I have also added RangeToHTML code from Ron De'Bruin.

Please assist me with the request.

Here is my code:

Sub Meeting_Request()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim rng As Range
Dim rng2 As Range
Dim myapt As Object ' Outlook.AppointmentItem

' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1

' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")

' Start at row 18
Sheets("Automation").Select
r = 18

Do Until Trim$(Cells(r, 1).Value) = ""
'Adding Goals and other details in email draft


Set rng = Nothing
On Error Resume Next
Set rng = Range("A9:A14").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If rng Is Nothing Then
    MsgBox "The selection is not a range or the sheet is protected" & _
           vbNewLine & "please correct and try again.", vbOKOnly
    Exit Sub
End If

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With




'Sheets("Automation").Select
' Create the AppointmentItem

Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
'Sheets("Automation").Select
With myapt
  .Subject = Sheets("Automation").Range("N" & r) & " day review"
  .Start = Sheets("Automation").Range("P" & r) & " " & "7:00:00 PM"
  .Duration = 0
  .Recipients.Add Sheets("Automation").Range("C" & r).Value & ";" & Sheets("Automation").Range("K" & r).Value
  .MeetingStatus = olMeeting
  ' not necessary if recipients are email addresses
  ' myapt.Recipients.ResolveAll
  '.AllDayEvent = "No"
    .BusyStatus = olBusy
   ' .BusyStatus = Cells(r, 5).Value
    .ReminderSet = False
  .HTMLBody = RangetoHTML(rng)
  .Save
  r = r + 1
  .Display
End With

Loop
End Sub
1

There are 1 best solutions below

0
On

Appointment items use the RTF markup for bodies instead of HTML (see the RTFBody property). So, you will not find the HTMLBody property for appointments. You can use the Word object model if you need to paste some HTML markup to the body. See Write HTML content to word document using C# for more information.

Starting from Outlook 2016 you can try to access the PR_HTML property which represents the HTML body using AppointmentItem.PropertyAccessor. The DASL name is http://schemas.microsoft.com/mapi/proptag/0x10130102.