I am trying to run working Outlook VBA code with VBScript.
The goal is to send a file from a location on drive to specified email address. This has to be recurring e.g. 7 am every day. Task Scheduler can do that I guess.
How do I create a vbs file to run the Outlook VBA code and link the vbs file to Task Scheduler?
Current macro:-
Dim fldName As String
Sub SendFilesbyEmail()
Dim sFName As String
i = 0
fldName = "\\blackstone.com\files\home\apac\gurgaon\Aggarwam\Settings\desktop\EXCEL FILES\Notes\"
sFName = Dir(fldName)
Do While Len(sFName) > 0
Call SendasAttachment(sFName)
sFName = Dir
i = i + 1
Debug.Print fName
Loop
MsgBox i & " files were sent"
End Sub
Function SendasAttachment(fName As String)
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim olAtt As Outlook.Attachments
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0) ' email
Set olAtt = olMsg.Attachments
' attach file
olAtt.Add (fldName & fName)
' send message
With olMsg
.Subject = "Here's that file you wanted"
.To = "[email protected]"
.HTMLBody = "Hi " & olMsg.To & ", <br /><br /> I have attached " & fName & " as you requested."
.Send
End With
End Function
Askeyword, everything in VBScript is aVariant. - Mathieu GuindonAsclauses everywhere, this is VBA code, VBScript doesn't run VBA code, it's two distinct languages. VBA runs VBScript, VBScript doesn't understand VBA. - Mathieu Guindon