从MSDocs复制的以下代码在我进行细微修改后引发错误。最初,绑定是早期而不是后期。但是,所有类型(Namespace
,SharingItem
)都是对象的类型。但是,如下面的示例中所示修改代码后,它将引发错误:
错误号-> -2147467259
错误说明->操作失败
错误源-> Microsoft Outlook
Sub MSCodeTest()
Dim oApp As Object 'Application --> added by me
Dim oNamespace As Object 'Namespace
Dim oFolder As Object 'Folder
Dim oSharingItem As Object 'SharingItem
On Error GoTo ErrRoutine
Set oApp = GetObject(, "Outlook.Application") 'added by me
Set oNamespace = oApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar)
Set oSharingItem = oNamespace.CreateSharingItem(oFolder)
oSharingItem.Display
EndRoutine:
On Error GoTo 0
Set oSharingItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Description, vbOKOnly, Err.Number & " - " & Err.source
GoTo EndRoutine
End Sub
另一方面,如果将Folder从Object
更改为Variant
,一切都会顺利进行。为什么将Folder
之类的对象类型项分配给Object
并引发错误,而分配给Variant
却不会出错?