title: How can I change this code so that it task scheduler can run it as a .vbs file?
body: <p>I have some vba code that sends an email with an attachment. it currently exists as a vba project in excel, but I would like to be able to save it as a vbs script so that I can fire it off every night with task scheduler. It only works in the project module I assume because I have to add a reference to an outlook library. If I save the script in notepad as a .vbs, it doesn't run.</p>
  
  <pre><code>Option Explicit
  
  Sub SendBasicEmail()
  
      Dim olApp As Outlook.Application
      Dim olEmail As Outlook.MailItem
  
      Set olApp = New Outlook.Application
      Set olEmail = olApp.CreateItem(olMailItem)
  
      With olEmail 
  
          .Display
          .Attachments.Add "FileDirectory"
          .To = "my email"
          .Subject = "Subject"
          .Send
  
      End With
  
  End Sub
  </code></pre>