attachment method issue

Discussion in 'Visual Basic ( VB )' started by firoz.raj, May 19, 2011.

  1. firoz.raj

    firoz.raj New Member

    Joined:
    May 19, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi friends. i have been trying to send excel sales file on email as attachment .but log file is comming as a attachment but excel file is not comming as a attachment .can you see the look? .Kindly let me know please .
    Code:
    [/SIZE]
       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 = "[EMAIL="application.support@alhokair.com.sa"]application.support@alhokair.com.sa[/EMAIL]"
            poSendMail.FromDisplayName = "Application Support"
            poSendMail.RecipientDisplayName = "firoz.mallik"
            poSendMail.Recipient = "[EMAIL="firoz.mallik@alhokair.com.sa"]firoz.mallik@alhokair.com.sa[/EMAIL]"
         '  poSendMail.Recipient = "[EMAIL="firoz.raj@gmail.com"]firoz.raj@gmail.com[/EMAIL]"
         '  poSendMail.CcRecipient = "[EMAIL="firoz.mallik@alhokair.com.sa"]firoz.mallik@alhokair.com.sa[/EMAIL]"
            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
    
    :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice