amcintosh
  • amcintosh
  • 52.25% (Neutral)
  • Newbie Topic Starter
4 months ago
Hi all

I'm trying to send an email containing the current workbook as an attachment, however the email being sent out without the file being attached, with no Error message shown either.

In the main sub - I call the function using the parameters below
eMailTo eto:=eto, ecc:=ecc, subj:=esub, body:=RangetoHTML(rng), attach:=ActiveWorkbook.FullName

and the function used here is -
Function eMailTo(eto, ecc, subj, body, attach)

Dim e
Set e = CreateObject("EaSEndMailObj.mail")
'Set e = New EASendMailObjLib.Mail

With e
.LicenseCode = (Removed) 
.ServerAddr = (Removed)
.UserName = (Removed)
.Password = (Removed)
.ServerPort = 25
.ConnectType = 4
.FromAddr = (Removed)
.AddRecipientEx eto, 0
.AddRecipientEx ecc, 1
.BodyFormat = 1
.BodyText = body
.Subject = subj
End With

If e.Addattachments(attach) <> 0 Then
MsgBox "Email Attachment Error: " & e.GetLastErrDescription()
End If
    Application.DisplayStatusBar = True
    Application.StatusBar = "Connecting " & e.ServerAddr & " ..."

    e.Asynchronous = 1
   ' InitVariables
'    CurrentEmailIsFinished = False
    e.SendMail

End Function

anybody know where i may have screwed up?
ivan
  • ivan
  • 100% (Exalted)
  • Administration
4 months ago
Hi, because opened workbook doesn't share read or write, so you cannot attach current workbook. You can save a copy of the workbook to the disk, then try to attached the copy.
amcintosh
  • amcintosh
  • 52.25% (Neutral)
  • Newbie Topic Starter
4 months ago
Thanks for your response,
I've added

tfile = "Pallet Movements for " & Format(Now, "dd-mm-yy") & ".xlsx"
ActiveWorkbook.SaveCopyAs tfile


If e.AddAttachments(tfile) <> 0 Then
MsgBox "Email Attachment Error: " & e.GetLastErrDescription()
End If

still no go unfortunately
ivan
  • ivan
  • 100% (Exalted)
  • Administration
4 months ago
Please use e.AddAttachment instead of AddAttachments.

AddAttachments adds all files in a folder, so the parameter should be a folder path, not a file.
If you want to add a file attachment, please use AddAttachment.

and please also use full file path instead of only file name.
amcintosh
  • amcintosh
  • 52.25% (Neutral)
  • Newbie Topic Starter
4 months ago
thanks for that, s.AddAttachment works 🙂

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.