GetObject(, "Outlook.Application") 不适用于 Outlook 打开

qag*_*fnz 5 excel outlook vba

我在 Excel 文件中使用以下代码,该文件可供多人访问和使用。在继续执行其余代码之前,提取会检查 Outlook 是否已打开。

Dim oOutlook As Object

'Checks to see if Outlook is open
On Error Resume Next
Set oOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0

If oOutlook Is Nothing Then
    MsgBox "Outlook is not open."
    Exit Sub
End If
Set oOutlook = Nothing
Run Code Online (Sandbox Code Playgroud)

除了一个人/计算机之外,该代码似乎适用于所有人。对于这一个人/计算机,即使打开 Outlook,该行代码 Set oOutlook = GetObject(, "Outlook.Application") 似乎也无法识别它已打开。我检查了通常的事情:确保 VBA 引用设置正确,安全设置似乎与其他人一样。

任何建议将不胜感激。

R3u*_*3uK 2

根据我的经验,我用它来避免这个问题:

On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
    Set oWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Run Code Online (Sandbox Code Playgroud)

但实际上我不知道问题出在哪里......有时它只是对我来说是擦肩而过!