User-defined type not defined for AppointmentItem in Excel

十年热恋 提交于 2019-12-04 06:56:36

问题


I copied example at http://support.microsoft.com/kb/220595 to the VBA in Excel.

My code follows:

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olAppt As Outlook.AppointmentItem
Set olAppt = olApp.CreateItem(olAppointmentItem)

I obtained the following error on the line Dim olAppt As Outlook.AppointmentItem: "User-defined type not defined".

How should this be fixed?

I use MS Office 2003.


回答1:


There are four prerequisite steps listed in that article. They are listed right before the code block.

You probably forgot to follow the step two, Adding a reference to Outlook object library.
The only difference is, in VBA the menu item is under Tools, not Project.




回答2:


You need to refer to all constants by their value, so, as olAppointmentItem = 1 :

 Set olAppt = olApp.CreateItem(1)

You can either look up values, for example http://msdn.microsoft.com/en-us/library/aa911356.aspx, or use Outlook's Object Browser to get the values.



来源:https://stackoverflow.com/questions/3645470/user-defined-type-not-defined-for-appointmentitem-in-excel

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