Code:
Public Sub SendMail(ByVal Attachmentfile As String)
Dim strMsg$
Dim filenumber%
Dim tmpfilename$
On Error GoTo errhnd
Set poSendMail = New vbSendMail.clsSendMail
poSendMail.SMTPHost = "mail.alhokair.com.sa"
' poSendMail.SMTPHost = "smtp.gmail.com"
poSendMail.AsHTML = True
poSendMail.From = "application.support@alhokair.com.sa"
poSendMail.FromDisplayName = "Application Support"
poSendMail.RecipientDisplayName = "firoz.mallik"
poSendMail.Recipient = "firoz.mallik@alhokair.com.sa"
' poSendMail.Recipient = "firoz.raj@gmail.com"
' poSendMail.CcRecipient = "firoz.mallik@alhokair.com.sa"
poSendMail.Subject = "CNK Sales summary _ China"
poSendMail.Message = "<html>" & vbCrLf & _
" <head> " & vbCrLf & _
"<title>Inditex Automated</title> " & vbCrLf & _
" </head> " & vbCrLf & _
" <body> " & vbCrLf & _
strMsg & vbCrLf & _
" </body> " & vbCrLf & _
" </html>"
poSendMail.Attachment = Attachmentfile
poSendMail.Send
Set poSendMail = Nothing
Exit Sub
errhnd:
If Err.Number <> 0 Then
logfilename = "C:\CNK\" & Format$(Now, "DDMMYYYY") & ".txt"
filenumber = FreeFile()
Open logfilename For Append As #filenumber
Print #filenumber, Err.Number, Err.Description, Now()
' Print #filenumber, Err.Description
Close #filenumber
End If
End Sub
Public Function CreateExcelSheet(ByRef rssales As ADODB.Recordset, path As String) As String
Dim i%
Dim filename$
i = 0
For Each adofields In rssales.Fields
osheet.Range("A1").Offset(0, i).Value = UCase(adofields.Name)
i = i + 1
Next
osheet.Range("A2").CopyFromRecordset rssales
osheet.Columns("H").Delete
osheet.Columns("A").Delete
objexcel.Application.DisplayAlerts = False
If Dir("C:\cnk", vbDirectory) = "" Then
MkDir "C:\CNK"
End If
filename = "C:\CNK\" & Format$(Date, "DDMMYYYY") & ".xls"
wbook.SaveAs path
wbook.Close
objexcel.Application.DisplayAlerts = False
objexcel.Quit
CreateExcelSheet = filename
Call SendMail(filename)
End Function
