问题
I am trying to copy data from Excel to Outlook appointment Item. I have already created a template with a table and some images and would like the data to be copied from the excel file in the already formatted table in the body of the template. However, unlike e-mail, outlook appointment does not support ".htmlbody"
property hence, its getting difficult to paste the data in the template.
So far, I am trying to do this:
Dim olAppItem as Outlook.AppointmentItem
Set olAppItem = olApp.CreateItemFromTemplate("C:\Users\User1\Desktop\Invite.oft")
The below two lines is where I am having a problem.
olAppItem.BodyFormat = olFormatRichtext
olAppItem.RTFBody = Replace(olAppItem.RTFBody, "%1%", "Test", , , vbDatabaseCompare)
I have tried setting olAppItem.Bodyformat
to olformatHTML
as well but it does not support the property.
Any help is appreciated.
Thanks.
回答1:
Please try this.
Private Sub Add_Appointments_To_Outlook_Calendar()
'Include Microsoft Outlook nn.nn Object Library from Tools -> References
Dim oAppt As AppointmentItem
Dim Remind_Time As Double
i = 2
Subj = ThisWorkbook.Sheets(1).Cells(i, 1)
'Loop through entire list of Reminders to be added
While Subj <> ""
Set oAppt = Outlook.Application.CreateItem(olAppointmentItem)
oAppt.Subject = Subj
oAppt.Location = ThisWorkbook.Sheets(1).Cells(i, 2)
oAppt.Start = ThisWorkbook.Sheets(1).Cells(i, 3)
Remind_Time = ThisWorkbook.Sheets(1).Cells(i, 4) * 1 * 60
oAppt.ReminderMinutesBeforeStart = Remind_Time
oAppt.AllDayEvent = True
oAppt.Save
i = i + 1
Subj = ThisWorkbook.Sheets(1).Cells(i, 1)
Wend
MsgBox "Reminder(s) Added To Outlook Calendar"
End Sub
' The code comes from this link:
http://officetricks.com/add-appointment-to-outlook-calendar-through-excel-macro-vba/
I wrote a book about these kinds of things, and a lot of other similar but different things. Check it out from the link below.
https://www.amazon.com/Automating-Business-Processes-Reducing-Increasing-ebook/dp/B01DJJKVZC?ie=UTF8&keywords=ryan%20shuell&qid=1463833985&ref_=sr_1_1&sr=8-1
来源:https://stackoverflow.com/questions/37025009/vba-outlook-appointment