我正在运行一个仪表板,每周刷新一次,使用ODBC连接。我写了一个运行在auto_open上的宏。该文件由Task Scheduler打开。发送Outlook电子邮件,范围从Excel工作表,电脑锁定时使用宏
系统: 的Windows 7 SP1, 展望2016年, 的Excel 2016
问题:当我安排与用户是否登录或没有设置为运行任务,Excel文件打开和被刷新,但它不会通过Outlook发送邮件,也不会显示在我的发件箱中。但刷新确实发生成功。这是用户没有登录的时候。当登录
用户
任务调度工作正常,我已经试过这Excel VBA - Email Does not Send When Computer is Locked并没有为我工作。
我使用发送邮件的功能是:
Dim oApp As Object, OutApp As Object, OutMail As Object
Dim rng As Range
Dim strbody As String, strtail As String
strbody = "Hi team," & "<br>" & _
"<a href=""https://example.com"">Here</a> is the link to cloud upload" & Worksheets("Core View").Range("M2") & "<br><br>"
strtail = "Thanks," & "<br>" & _
"Team." & "<br><br>"
On Error Resume Next
'Only the visible cells in the selection
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = Sheets("Core View").Range("A7:K106").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected. " & _
vbNewLine & "Please correct and try again.", vbOKOnly
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
'Create the mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "[email protected]"
.CC = ""
.BCC = ""
If EmptySheets <> "" Then
.Subject = "update has issues in " & EmptySheets
Else
.Subject = "Update for week" & Worksheets("Core View").Range("M2")
End If
.HTMLBody = strbody & RangetoHTML(rng) & strtail
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Function
当没有用户登录,也没有Outlook帐户的访问来发送邮件。我不希望任何事情能够抓住Outlook并开始倾销电子邮件 - 你会吗?这通常是恶意软件用于表现的原因,这正是Outlook现在不允许它的原因。 –
@KenWhite我很抱歉,但我的意思是电脑被锁定,当我写道“这是当用户没有登录。”但是,你说什么是有道理的。令我惊讶的是,它在计算机没有锁定时有效。 – Plaknas
我说的话适用于用户没有登录时,这是我理解你的意思*这是当用户没有登录时*。 :-) –