2009-08-14 31 views

答えて

4
Dim Process, strObject, strProcess 
Const strComputer = "." 
strProcess = "OUTLOOK.exe" 
IsProcessRunning = False 
strObject = "winmgmts://" & strComputer 
For Each Process in GetObject(strObject).InstancesOf("win32_process") 
If UCase(Process.name) = UCase(strProcess) Then 
     MsgBox "Outlook is running" 
    End If 
Next 
+0

注意...私のvista64バージョンはwin32_processのインスタンスになる予定ですか? – Karl

7

あなたはGetObject機能を使用してOutlook Applicationオブジェクトを取得してみてください。関数呼び出しが成功した場合、これは、Outlookが現在実行されていることを意味します

On Error Resume Next 
Dim Outlook: Set Outlook = GetObject(, "Outlook.Application") 

If Err.Number = 0 Then 
    ' Outlook is running 
Else 
    ' Outlook is not running 
    Err.Clear 
End If 

On Error Goto 0 
+2

私はあなたがコンマ(パス名、クラス)を必要とすると思います:GetObject( "Outlook.Application") – Fionnuala

+0

プロシージャ内の他のエラーが抑制されないように、最後に 'On Error Goto 0'を追加することがあります。 –

0

コールCheckOutlookAndSendEmail

サブMailViaOutlook() 薄暗いOutApp 点心OutMail 設定OutApp =のCreateObject( "Outlook.Application") 設定しOutMail = OutApp.CreateItem(0)

On Error Resume Next 
With OutMail 
    .to = "youremailid" 
    .CC = "" 
    .BCC = "" 
    .Subject = "your Subject" 
    .Body =" Thanks - .......:)" 

    .Send 
End With 
On Error GoTo 0 

Set OutMail = Nothing 
Set OutApp = Nothing 

End Subの

エンド機能が

サブCheckOutlookAndSendEmailを()

dim Process, strObject, strProcess 
Const strComputer = "." 
strProcess = "OUTLOOK.exe" 
strObject = "winmgmts://" & strComputer 
For Each Process in GetObject(strObject).InstancesOf("win32_process") 
    If UCase(Process.name) = UCase(strProcess) Then 
     call MailViaOutlook ' no need to open outlook as it is already open, Hence using the exesting and send email 
     exit sub   
    end if 

Next 
call OpenOutlook ' Open Outlook 
call MailViaOutlook ' send email using outlook 

場合OpenOutlook '関数以下は、エンドサブ

Dim WshShell 
Set WshShell=WScript.CreateObject("WScript.Shell") 
WshShell.run "Outlook" 
If Err <> 0 then 
    Err.Clear 
    Set ObjOL= CreateObject("Outlook.Application") 
End If 

オープン見通し

サブOpenOutlook()のためのものです'

End Sub

関連する問題