I am trying to write a macro that will take all of the .xls files in a folder then create and add them to an email. I have been able to get a list of all of the files and I have been able to generate an email with an attachment but I have not been able to do both. Here is my code"
Code:
Sub asd()
Dim objol As New Outlook.Application
Dim objmail As MailItem
Set objol = New Outlook.Application
Set objmail = objol.CreateItem(olMailItem)
Dim fso As Object
Dim strName As String
Dim strArr(1 To 65536, 1 To 1) As String, i As Long
Dim testa As String
Const strDir As String = "\\sales-a\current tickets\Mass Macro"
Const searchTerm As String = ""
Let strName = Dir$(strDir & "\*" & searchTerm & "*.xls")
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = strDir & "\" & strName
Let strName = Dir$()
Let testa = (strDir & "\" & strName) & "; " & testa
Loop
Set fso = CreateObject("Scripting.FileSystemObject")
Set fso = Nothing
If i > 0 Then
' MsgBox testa
End If
With objmail
.To = "me"
.CC = ""
.Subject = "Ticket " & Today & " " & Name
.Body = MyValue
.NoAging = True
.Attachments.Add testa
.Display
End With
Set objmail = Nothing
Set objol = Nothing
End Sub