title: Windows Task Manager Schedule VBA Macro to Send An Email Using OutLook Daily Running Manually and Not Automatically
body: <p>I have my macro which is running, &amp; for this I created a vb script and used windows task manager to schedule its run every day.</p>
  
  <p>Whenever I run manually or attempt changing the time in the trigger, I always make sure that both excel and outlook are not running.
  If I run the macro in Excel VBA, it sends the email.
  After scheduling the task to run everyday, just as a test if I go to (in TaskScheduler) View -> Hidden Tasks and manually click Run, it sends the email.</p>
  
  <p>However, if I schedule it to run at a specific time everyday, say maybe starting today, 15 minutes from now, it does not send the email &amp; the last run result is (0x0). </p>
  
  <p>I have enabled all macros in the trust center settings and selected 'Trust access to the VBA project object model', &amp; it's not an issue about administrator privileges. 
  This is my VB script</p>
  
  <pre><code>Dim ObjExcel, ObjWB
  Set ObjExcel = CreateObject("Excel.Application")
  Set ObjWB = ObjExcel.Workbooks.Open("C:\Users\myUser\MyLocation\MyFile.xlsm")
  ObjExcel.Visible = False
  ObjExcel.DisplayAlerts = False
  ObjExcel.AskToUpdateLinks = False
  ObjExcel.AlertBeforeOverwriting = False
  
  'vbs opens a file specified by the path below
  'either use the Workbook Open event (if macros are enabled), or Application.Run
  
  ObjExcel.Application.Run "MyFile.xlsm!main_macro"
  ObjWB.Save
  ObjWB.ActiveWorkbook.Close
  ObjExcel.Quit
  
  Set ObjWB = Nothing
  Set ObjExcel = Nothing
  WScript.Echo "Finished."
  WScript.Quit
  </code></pre>
  
  <p>Also, here are my TaskScheduler Settings:</p>
  
  <p><a href="https://i.stack.imgur.com/XcBjW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XcBjW.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ps9de.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ps9de.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/PAkaX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PAkaX.jpg" alt="enter image description here"></a></p>
  
  <p>Ref:</p>
  
  <p><a href="https://stackoverflow.com/questions/31189863/sending-email-from-excel-automatically-based-on-date">Sending email from excel automatically based on date</a></p>
  
  <p><a href="https://stackoverflow.com/questions/22771185/how-to-set-recurring-schedule-for-xlsm-file-using-windows-task-scheduler/22789150#22789150">How to set recurring schedule for xlsm file using Windows Task Scheduler</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8914703/how-can-you-run-an-excel-macro-through-a-schedule-task/17632087#17632087">How can you run an Excel macro through a schedule task</a></p>
  
  <p><a href="https://stackoverflow.com/questions/37555107/task-scheduler-does-not-run-excel-vba-code-to-send-pdf-as-email-attachment/37557589#37557589">Task Scheduler does not run Excel VBA Code to send PDF as Email Attachment</a></p>
  
  <p>If I set the below to <code>True</code>:</p>
  
  <pre><code>ObjExcel.Visible = False
  ObjExcel.DisplayAlerts = False
  ObjExcel.AskToUpdateLinks = False
  ObjExcel.AlertBeforeOverwriting = False
  </code></pre>
  
  <p>Excel opens in read-only mode and says click notify to receive the notification that you can now edit the workbook but I cannot edit it, says another user has the workbook open for editing.</p>