问题
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