VBA Outlook Appointment

馋奶兔 提交于 2020-01-13 07:11:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!