L42*_*L42 7 vbscript vba outlook-vba
我在Outlook中有一个过程,它将所有已保存的消息发送到Drafts文件夹中.
以下是代码:
Public Sub SendMail()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim olDraft As Outlook.MAPIFolder
Dim strfoldername As String
Dim i As Integer
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
strfoldername = olFolder.Parent
Set olDraft = olNS.Folders(strfoldername).Folders("Drafts")
If olDraft.Items.Count <> 0 Then
For i = olDraft.Items.Count To 1 Step -1
olDraft.Items.Item(i).Send
Next
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
以上代码工作正常.
题:
我想用它Task Scheduler来指定这个程序.
1.我将把程序放在Outlook,Module或ThisOutlookSession中?
2.我不擅长,vbscript所以我也不知道如何编写代码来调用Outlook程序.我已经完成了调用Excel Procedure但Outlook不支持.Run属性.
所以这不起作用:
Dim olApp
Set olApp = CreateObject("Outlook.Application")
olApp.Run "ProcedureName"
Set olApp = Nothing
Run Code Online (Sandbox Code Playgroud)
我也读过Session.Logon这样的话:
Dim olApp
Set olApp = CreateObject("Outlook.Application")
olApp.Session.Logon
olApp.ProcedureName
Set olApp = Nothing
Run Code Online (Sandbox Code Playgroud)
但它会引发错误,说不ProcedureName支持对象.
希望有人可以解释一下.
解:
好吧,我已经想出了2个可以避免或者通过这个弹出窗口的工作.

第一个:就像KazJaw指出的那样.
假设您有另一个程序(例如Excel,VBScript),其中包括通过Outlook程序发送邮件.
而不是使用.Send,只是.Save邮件.
它将保存在Outlook's Draft文件夹中.
然后使用下面的代码,发送使用的草稿Outlook Task Reminder.
Option Explicit
Private WithEvents my_reminder As Outlook.Reminders
Private Sub Application_Reminder(ByVal Item As Object)
Dim myitem As TaskItem
If Item.Class = olTask Then 'This works the same as the next line but i prefer it since it automatically provides you the different item classes.
'If TypeName(Item) = "TaskItem" Then
Set my_reminder = Outlook.Reminders
Set myitem = Item
If myitem.Subject = "Send Draft" Then
Call SendMail
End If
End If
End Sub
Private Sub my_reminder_BeforeReminderShow(Cancel As Boolean)
Cancel = True
Set my_reminder = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
当Task Reminder主题为"发送草稿"的节目时,上面的代码会触发.
但是,我们不希望它显示,因为整个观点只是调用SendMail程序.
所以我们添加了一个程序,Cancels显示olTask类或TaskItem类型的提醒.
这Outlook当然需要运行.
您可以像我一样保持24小时运行,或者创建一个VBscript打开它以便通过它安排Task Scheduler.
第二个:Allow当安全弹出窗口出现时,使用API以编程方式单击按钮.
致SiddarthRout的帮助.
这是LINK,它将帮助您以编程方式单击Allow按钮.
当然你需要调整一下.
经过尝试和测试!
假设您的 Outlook 应用程序始终运行(根据问题下面的评论),您可以按照以下步骤执行您需要的操作:
在 Outlook 中添加一个新任务,设置主题为:“运行宏 YourMacroName”并设置宏应启动的时间(加上周期)。
转到VBA编辑器,打开ThisOutlookSession module并在里面添加以下代码(另请参阅代码内的注释):
Private Sub Application_Reminder(ByVal Item As Object)
If TypeName(Item) = "TaskItem" Then
Dim myItem As TaskItem
Set myItem = Item
If myItem.Subject = "run macro YourMacroName" Then
Call YourMacroName '...your macro name here
End If
End If
End Sub
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
13869 次 |
| 最近记录: |