如何使用 VBA 验证 Outlook 会话是否打开 [英] How to verify outlook session is open or not using VBA

查看:47
本文介绍了如何使用 VBA 验证 Outlook 会话是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 VBA 宏,它从 Excel 中的 LN 中提取报告并向我的经理发送邮件.我使用调度程序使用 .vbs 脚本运行这个宏.此调度程序从周一至周五的早上运行.这里的问题是我们有时会在周六和周日为我们的系统提供服务.周日和因为展望会议接近尾声.

I have VBA Macro which extract report from LN in Excel and sent out a mail to my manager's. I have used scheduler to run this MACRO using .vbs script. This scheduler run from Monday - Friday in the morning. the problem here is we sometime have a servicing going with our system during Sat & Sunday and coz of that the outlook session get close.

我在这里想要的是我想编写一个 VBA 宏,它首先验证 Outlook 会话是否打开,如果它打开,那么我们就可以了,如果不是我们需要打开 Outlook 会话并发送邮件.

What I want here is i want to write a VBA macro which will first verify that Out look session is open or not if it is open then we are fine if not we need to open the outlook session and send the mail.

需要你的专业知识:)

推荐答案

尝试使用 GetObject(,"Outlook.Application") 获取对正在运行的 Outlook 会话的引用 - 如果失败则您可以使用 CreateObject() 启动 Outlook

Try to use GetObject(,"Outlook.Application") to get a reference to a running Outlook session - if that fails then you can use CreateObject() to start Outlook

Dim olApp As Outlook.Application

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error Goto 0 

If olApp Is Nothing Then
    Set olApp = CreateObject("Outlook.Application")
End If

If olApp Is Nothing Then
    Err.Raise 999, , "Failed to get Outlook reference"
End If

这篇关于如何使用 VBA 验证 Outlook 会话是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆