Using Excel VBA, I'd like to make a small pivot table visible to Outlook users.
I do NOT want to paste into a message body
I DO want to paste into an appointmentItem
Here is my code that creates the Appointment and copies Range to clipboard.
How do I paste it into Oapt.Body? (there is no Oapt.HTMLbody)
Option Explicit
Public Sub DailySummary()
Dim errorMsg As String
'library references are set, this is early binding technique:
Dim Oapp As Outlook.Application
Dim Onsp As Namespace
Dim OcaF As Outlook.Folder
Dim Oapt As AppointmentItem
Sheets("DailySummary").Select
errorMsg = "Get/CreateObject(""Outlook.Application"") - Failed"
On Error Resume Next
Set Oapp = GetObject("Outlook.Application") 'assume Outlook is running
If Error <> 0 Then 'if Outlook NOT running
Set Oapp = CreateObject("Outlook.Application") 'get Outlook running
End If
On Error GoTo err
errorMsg = "oApp.GetNamespace(""MAPI"") - Failed"
Set Onsp = Oapp.GetNamespace("MAPI")
On Error GoTo 0
errorMsg = "Oapp.CreateItem(olAppointmentItem) - Failed"
Set Oapt = Oapp.CreateItem(olAppointmentItem)
errorMsg = "Set Up AppointmentItem - Failed"
With Oapt
.Subject = "SPC Daily Summary"
.Start = Range("B6").Value + 0.3333333 '8am on the date in B6 in the PT.
.Duration = 60
.AllDayEvent = False
.Importance = olImportanceNormal
.Location = "St Paul's Centre"
.Body = "Team SPC Daily Duties"
.ReminderSet = True
.ReminderMinutesBeforeStart = "60"
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.wav"
.Attachments.Add Range("Downloads") & "\" & "TestAttachment.pdf", olByValue, 0
ActiveSheet.PivotTables(1).TableRange1.CopyPicture xlScreen, xlBitmap
.Body = RangetoHTML(Worksheets("DailySummary").Range("B5:K20"))
'--------------------------------------------------------------------------
' here's where I am STUCK!
' how do I paste into the body of the "olAppointmentItem" ?
'--------------------------------------------------------------------------
errorMsg = "cannot Save appointment"
'.Display
.Save
End With
MsgBox "Appointment Created:" & vbCr & vbCr & _
"App: " & Oapp & ", Namespace: " & Onsp & vbCr & _
"Apointment: " & Oapt.Subject & vbCr & _
" " & Oapt.Start, _
vbOK, "SPC Bookings"
'Happy Ending
GoTo exitsub
'Unhappy ending
Err:
MsgBox err.Number & " " & errorMsg, vbCritical, "SPC Bookings"
Exitsub:
Set Oapp = Nothing
Set Onsp = Nothing
Set Oapt = Nothing
End Sub`