计算机被锁定时如何发送电子邮件? [英] How to Send Email When Computer is Locked?
问题描述
我想使用 Excel VBA 发送 Outlook 电子邮件.
代码 Sendupdate
在手动运行时有效.
我的第二个宏 StartTimer
用于在我不在办公桌前的设定时间执行上述操作.
当计算机被锁定时,电子邮件不会发送.当我回到我的办公桌时,电子邮件作为草稿挂在那里,我需要点击 send
按钮.
Sub SendUpdate()收件人 = x@y.com"Subj = 更新"Dim msg 作为字符串msg =你好"HLink = "mailto:"&收件人&?"HLink = HLink &主题="&主题&&"HLink = HLink &身体="&留言ActiveWorkbook.FollowHyperlink (HLink)Application.Wait(现在 + 时间值(0:00:01"))Application.SendKeys%s"结束子子启动定时器()Application.OnTime TimeValue("18:00:00"), "SendUpdate"结束子
有没有办法确保电子邮件被推送?
我将把这个教程"分成 3 个步骤
1) 编写 Excel 宏
2) 准备你的 vbscript 文件
3) 在 Windows Task Scheduler 中设置任务
<小时>编写 EXCEL 宏
<小时>在 Excel 中打开一个新文件并在模块中粘贴此代码
选项显式Const strTo As String = "abc@abc.com"Const strCC As String = "def@abc.com" '<~~ 把"def@abc.com" 改为 "" 如果你不想抄送Const strBCC As String = "ghi@abc.com" '<~~ 如果不想密件抄送,请将"ghi@abc.com"改为""子样本()Dim OutApp 作为对象,OutMail 作为对象Dim strbody As String, strSubject As StringstrSubject = "你好世界"strbody = "这是给身体的信息"Set OutApp = CreateObject("Outlook.Application")设置 OutMail = OutApp.CreateItem(0)出错时继续下一步使用 OutMail.To = strTo.CC = strCC.BCC = strBCC.Subject = "这是主题行".body = strbody.发送结束于出错时转到 0设置 OutMail = 无设置 OutApp = 无结束子
将 Excel 文件另存为 C:Tester.Xlsm
如果您使用的是 Excel 2007 或 C:Tester.Xls
如果您使用的是 Excel 2003 并退出
准备 VBSCRIPT 文件
<小时>打开记事本,然后粘贴此代码.根据需要更改扩展名.xls".
Dim xlApp昏暗的 xlBookSet xlApp = CreateObject("Excel.Application")Set xlBook = xlApp.Workbooks.Open("C:Tester.xls", 0, True)xlApp.运行示例"xlBook.ClosexlApp.退出设置 xlBook = 无设置 xlApp = 无
将文件另存为 Tester.vbs
并关闭它
在 WINDOWS 任务调度程序中设置任务
<小时><块引用><块引用><块引用>您能确认您的 Windows 操作系统吗?– Siddharth Rout 36 分钟前
Windows XP.它是我的工作计算机(所以有通常的登录等).– 凯恩斯克罗斯 18 分钟前
点击开始按钮 |所有程序 |配件 |系统工具 |安排任务以获取此窗口
双击Add Scheduled Task"进入这个窗口
点击下一步
点击浏览"并选择我们之前创建的vbs文件并点击打开"
您获得的下一个窗口至关重要,因为我们需要在此处提及脚本何时需要运行
完成必要的操作后,点击下一步.
在此窗口中,输入您的登录详细信息,以便即使在屏幕锁定时脚本也能运行.
完成后单击下一步",然后在下一个窗口中单击完成".您的任务计划程序现在看起来像这样
大功告成
<小时>锁上你的电脑,然后去喝杯咖啡;) 当你回来时(取决于你在任务计划程序中设置的时间和休息时间),电子邮件本来是发送.
HTH
I want to send Outlook emails using Excel VBA.
The code Sendupdate
works when run manually.
My second macro StartTimer
is intended to execute the above at a set time when I am not at my desk.
When the computer is locked the email does not send. When I come back to my desk the email is hanging there as a draft, and I need to click the send
button.
Sub SendUpdate()
Recipient = "x@y.com"
Subj = "update"
Dim msg As String
msg = "hello"
HLink = "mailto:" & Recipient & "?"
HLink = HLink & "subject=" & Subj & "&"
HLink = HLink & "body=" & msg
ActiveWorkbook.FollowHyperlink (HLink)
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys "%s"
End Sub
Sub StartTimer()
Application.OnTime TimeValue("18:00:00"), "SendUpdate"
End Sub
Is there a way to make sure the email gets pushed?
I will break this "Tutorial" in 3 steps
1) Writing your Excel Macro
2) Preparing your vbscript file
3) Setting the task in Windows Task Scheduler
WRITING THE EXCEL MACRO
Open a new File in Excel and in the module, paste this code
Option Explicit
Const strTo As String = "abc@abc.com"
Const strCC As String = "def@abc.com" '<~~ change "def@abc.com" to "" if you do not want to CC
Const strBCC As String = "ghi@abc.com" '<~~ change "ghi@abc.com" to "" if you do not want to BCC
Sub Sample()
Dim OutApp As Object, OutMail As Object
Dim strbody As String, strSubject As String
strSubject = "Hello World"
strbody = "This is the message for the body"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = strTo
.CC = strCC
.BCC = strBCC
.Subject = "This is the Subject line"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Save the Excel File as C:Tester.Xlsm
if you are using Excel 2007 onwards or C:Tester.Xls
if you are using Excel 2003 and exit
PREPARING THE VBSCRIPT FILE
Open Notepad and then paste this code. Change the extension ".xls" as applicable.
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:Tester.xls", 0, True)
xlApp.Run "Sample"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
Save the File as Tester.vbs
and close it
SETTING UP THE TASK IN WINDOWS TASK SCHEDULER
Could you confirm your windows operating system? – Siddharth Rout 36 mins ago
Windows XP. Its my work computer (so has the usual logins etc). – keynesiancross 18 mins ago
Click on the Start Button | All Programs | Accessories | System Tools | Schedule Tasks to get this window
Double click on "Add Scheduled Task" to get this window
Click Next
Click on "Browse" and select the vbs file that we created earlier and click on "open"
The next window that you get is crucial as it is here we need to mention when script needs to run
After you have done the needful, click on next.
In this window, enter your login details so that the script can run even when your screen is locked.
Click "Next" when done and then click "Finish" in the next window. Your task scheduler now looks like this
And you are done
Lock your pc and go take a coffee break ;) When you come back (depending on what time you set in the task scheduler and how much time is your break), the email would have been sent.
HTH
这篇关于计算机被锁定时如何发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!