问题的简单形式是这样。

if outlook.application "is available" then
      'run the command for sending an email
else
      'open/display the current users document folder
end if

'do some stuff...

我的电子邮件功能本身很好用,但是我似乎无法弄清楚如何测试Outlook并绕过显示文件夹...

最佳答案

以下代码首先检查Outlook是否已在运行。如果是这样,则将应用程序分配给olApp。如果没有,它将启动应用程序(如果可用),并将其分配给olApp。

Dim olApp As Object

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then
    Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0

If Not olApp Is Nothing Then
    'run the command for sending an email
Else
    'open/display the current users document folder
End If

'do some stuff...

Set olApp = Nothing

09-25 17:09