how to test for outlook in a specific scenario

前端 未结 1 1054
梦如初夏
梦如初夏 2021-01-29 06:04

The simple version of the question is this.

if outlook.application \"is available\" then
      \'run the command for sending an email
else
      \'open/display          


        
相关标签:
1条回答
  • 2021-01-29 06:31

    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
    
    0 讨论(0)
提交回复
热议问题