interaction with excel is working but not working with outlook
I am able to schedule the below task in the task scheduler in " user is logged on or not" mode and it is working fine. (running from VBS file)
Sub runTaskTest()
Dim erow As Long
erow = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
Sheets(1).Cells(erow + 1, 1).Value = "This test was successful : " & Now
ThisWorkbook.Saved = True
ThisWorkbook.Save
End Sub
but when i try to send an automatic email from outlook using excel vba macro scheduler is failed to run with the option "whether user is logged on or not"
Sub runTaskTest()
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
With OutlookMail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "Dear ABC" & "<br>" & "<br>" & "Please find the attached file" &
.HTMLBody
'last .HTMLBody includes signature from the outlook.
''<br> includes line breaks
b/w two lines
.To = "abc@gmail.com"
.Subject = "Test mail"
.Attachments = ThisWorkbook
.Send
End With
End Sub
VBScript
Option Explicit
Dim xlApp
Dim xlBook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\Excel_Test\excel_test.xlsm", 0, False)
xlApp.DisplayAlerts = False
xlApp.Visible = False
xlApp.Run "'excel_test.xlsm'!runTaskTest" // **
xlBook.Saved = True
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
but same code is working fine when I select " Run only when user logged on"
I tried the below solutions but nothing helps
created empty folder in "C:\Windows\System32\config\systemprofile\Desktop" refered enter link description here
checked all the privileges and rights to run the tasks( log on as batch job )
but nothing helps. kindly help me to resolve the issue.