VBA kode email alle filer fra folder.
Denne stump kode har jeg benyttet i adskillige år, men den virker kun på navngivne filer :-(Jeg har behov for at vedhæfte alle filer fra den pågældende folder
vedhæftet.Add "W:\Data Collector, DWH.nodlt\Elspot Price calculator\Released Calculations\ALLEFILER"
Public Function SendEmail()
Dim objOl As New Outlook.Application
Dim objPost As MailItem
Dim vedhæftet As Attachments
Dim MyDB As DAO.Database
Dim MyRS As Recordset
Dim TOAddress As String
Dim CCAddress As String
Set objPost = objOl.CreateItem(olMailItem)
Set vedhæftet = objPost.Attachments
vedhæftet.Add "W:\Data Collector, DWH.nodlt\Elspot Price calculator\Released Calculations\Fil01.xlsm"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMailingList")
MyRS.MoveFirst
TOAddress = MyRS![To]
CCAddress = MyRS![CC]
With objPost
.Subject = "Weekly Electricity Price Calculation"
.To = TOAddress
.CC = CCAddress
.HTMLBody = "This is an autogenerated message"
.Send
'.Display
End With
'objOl.Quit
Set objPost = Nothing
Set vedhæftet = Nothing
Exit Function
errhandler:
MsgBox "ERROR: " & Err.Number & " - " & Err.Description
End Function