我在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
上面的代码工作正常。
问题:
我想使用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
我也读过Session.Logon
这样的内容:
Dim olApp
Set olApp = CreateObject("Outlook.Application")
olApp.Session.Logon
olApp.ProcedureName
Set olApp = Nothing
但是它抛出错误,指出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
Task Reminder
带有主题“发送草稿”的节目时,上面的代码将触发。
但是,我们不希望它显示出来,因为整个过程只是为了调用SendMail
过程。
因此我们添加了一个程序,Cancels
该程序显示提醒是olTask
类还是TaskItem
类型。
这Outlook
当然需要运行。
您可以像我一样将其保持24小时运行,也可以创建一个VBscript
通过预定的打开它Task Scheduler
。
第二个:在Allow出现安全弹出窗口时,使用API以编程方式单击按钮。
感谢SiddarthRout的帮助。
这是LINK,可帮助您以编程方式单击该Allow按钮。
当然,您必须对其进行一些调整。
尝试和测试!
假设您一直在运行Outlook Application(根据问题下方的评论),您可以按照以下步骤进行操作:
在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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句