I am trying to do exactly what I said in the subject but am beating my head against the wall. When I take out the code from below that attaches the files, the email works great. When I try to attach files as below, it doesn't send anything...it also doesn't give me any errors. Any ideas?
Thanks in advance.
Code:
Option Explicit
Private Const S_OK = &H0 ' Success
Private Const S_FALSE = &H1 ' The Folder is valid, but does not exist
Private Const E_INVALIDARG = &H80070057 ' Invalid CSIDL Value
Private Const CSIDL_LOCAL_APPDATA = &H1C&
Private Const CSIDL_FLAG_CREATE = &H8000&
Private Const SHGFP_TYPE_CURRENT = 0
Private Const SHGFP_TYPE_DEFAULT = 1
Private Const MAX_PATH = 260
Private Declare Function SHGetFolderPath Lib "shfolder" _
Alias "SHGetFolderPathA" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
ByVal hToken As Long, ByVal dwFlags As Long, _
ByVal pszPath As String) As Long
Public Function SendEmail()
Dim strEmailMsg As String
Dim mydocPath As String
Dim RetVal As Long
Dim MyName As String
Dim fso As Scripting.FileSystemObject
Dim myFolder As Scripting.Folder
Dim myFile As Scripting.File
Dim strTemp As String
Dim intRtn, intX As Integer
On Error Resume Next
mpSession.SignOn
mpMessage.SessionID = mpSession.SessionID
mpMessage.RecipDisplayName = "Joe.Smith@emailing.ca"
mpMessage.RecipAddress = "Joe Smith"
mpMessage.AddressResolveUI = True
mpMessage.ResolveName
mpMessage.Compose
mpMessage.MsgSubject = "This is the subject"
strEmailMsg = "This is the email text"
mpMessage.MsgNoteText = strEmailMsg
mydocPath = "c:\batch\statistics\result\main"
Set fso = Nothing 'these lines re-initialize the files in the array
Set myFolder = Nothing
Set fso = New Scripting.FileSystemObject
Set myFolder = fso.GetFolder(mydocPath)
For Each myFile In myFolder.Files
mpMessage.AttachmentIndex = intX
mpMessage.AttachmentPosition = intX
mpMessage.AttachmentType = 0
strTemp = myFile.Name 'turns the filename into a string variable
mpMessage.AttachmentPathName = mydocPath & "\" & strTemp
intX = intX + 1
Next
mpMessage.Send False
mpSession.SignOff
End Function
Private Sub Form_Load()
SendEmail
End
End Sub
Thanks in advance.