Код:
Function GetAttach()
Dim strPath
Dim arrFiles
strPath = "C:\test"
Set arrFiles = CreateObject("Shell.Application").NameSpace(strPath).Items
arrFiles.Filter 64, "*.xls"
Select Case arrFiles.Count
Case 0
MsgBox "Отчет для отправки не найден.", 48, "Отправка файла"
WScript.Quit 1
Case 1
GetAttach = arrFiles.Item(0).Path
Case Else
MsgBox "Найдено несколько файлов.", 48, "Отправка файла"
WScript.Quit 1
End Select
End Function
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Sub AutoSendMail()
' Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Set OutApp = CreateObject("Outlook.Application")
Outlook.ActiveWindow.WindowState = 1
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B></B></H3>" & _
"Суточный отчет.<br>" & _
"Подразделение.<br>
SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\UserName.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.To = "adress@domain"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br><br>" & Signature
.Attachments.Add GetAttach
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub