vba - Sending an Outlook email with range from Excel sheet, using Macro when the Computer is locked -


i running dashboard refreshes weekly, using odbc connection. have written macro runs on auto_open. file getting opened task scheduler.

system: windows 7 sp1, outlook 2016, excel 2016

problem: when schedule task setting run whether user logged on or not, excel file opens , gets refreshed, not send out mail via outlook, nor appear in outbox. refresh happen though. when user not logged on.

the task schedule works fine when user logged on

i have tried excel vba - email not send when computer locked , did not work me.

the function using sending mail is:

dim oapp object, outapp object, outmail object dim rng range dim strbody string, strtail string  strbody = "hi team," & "<br>" & _          "<a href=""https://example.com"">here</a> link cloud upload" & worksheets("core view").range("m2") & "<br><br>" strtail = "thanks," & "<br>" & _ "team." & "<br><br>"     on error resume next     'only visible cells in selection     'set rng = selection.specialcells(xlcelltypevisible)     set rng = sheets("core view").range("a7:k106").specialcells(xlcelltypevisible)     on error goto 0       if rng nothing         msgbox "the selection not range or sheet protected. " & _                vbnewline & "please correct , try again.", vbokonly     end if      application         .enableevents = false         .screenupdating = false     end      'create mail     set outapp = createobject("outlook.application")     set outmail = outapp.createitem(0)      on error resume next     outmail         .to = "plaknas@example.com"         .cc = ""         .bcc = ""         if emptysheets <> ""         .subject = "update has issues in " & emptysheets         else         .subject = "update week" & worksheets("core view").range("m2")         end if         .htmlbody = strbody & rangetohtml(rng) & strtail         .send   'or use .display     end     on error goto 0 application .enableevents = true .screenupdating = true end set outmail = nothing set outapp = nothing end function 

you cannot use outlook object model in script or program run task scheduler or windows service. security context quite different , code won't run intended:

https://support.microsoft.com/en-us/kb/237913


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -