我在stackoverflow上找到了下面的优秀VBA代码,当我第一次将它包含在测试工作簿中时,它运行得很好。然后我将相同的代码放入我想要最终使用此代码的工作簿中,并在运行模块时收到此错误:
"编译错误:用户定义的类型未定义"
我还没能确定我收到此错误的原因。调试器告诉我以下行是问题:
Dim oNameSpace As Namespace
Sub Create_Outlook_3()
Dim oApp As Object
Dim oNameSpace As Namespace
Dim oFolder As Object
Dim wsSrc As Worksheet
Set wsSrc = Sheets("OutlookCalExport")
' Start looping at row 3 (first two rows are for readability)
r = 3
' Do/while set condition
Do Until Trim(wsSrc.Cells(r, 1).Value) = ""
' Create the Outlook session
Set oApp = New Outlook.Application
' Set the namespace
Set oNameSpace = oApp.GetNamespace("MAPI")
' Set the folder the appointment will be created in.
Set oFolder = oNameSpace.GetFolderFromID("000000002779752072EF5A42849125C847A02A8AE2800000").Items.Add(olAppointmentItem)
' Set with block for the appointment configuration loop
With oFolder
' Set Subject line of event
.Subject = wsSrc.Cells(r, 1).Value & " " & wsSrc.Cells(r, 2).Value
' Set start time
.Start = DateValue(wsSrc.Cells(r, 3)) + wsSrc.Cells(r, 8).Value
' Set end time
.End = DateValue(wsSrc.Cells(r, 3)) + wsSrc.Cells(r, 9).Value
' Turn reminders off
.ReminderSet = False
' Set busy status to free
.BusyStatus = 0
' Have the body of the event read as the decription from the leave form in Viewpoint
.Body = wsSrc.Cells(r, 4).Value
' Save event in owners calendar
.Save
' End with block
End With
' Move to next row
r = r + 1
' Repeat do/while loop until condition is no longer valid
Loop
End Sub
我感谢你们所能提供的任何帮助!