how to test for outlook in a specific scenario

雨燕双飞 提交于 2019-12-20 07:47:23

问题


The simple version of the question is this.

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...

I the email function works great on its own, but i cannot seem to figure out how to test for outlook and bypass to displaying the folder...


回答1:


The following code first checks whether Outlook is already running. If so, the application is assigned to olApp. If not, it starts the application, if available, and assigns it to 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


来源:https://stackoverflow.com/questions/51796218/how-to-test-for-outlook-in-a-specific-scenario

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!