The macro was for Outlook VBA. If you are creating a macro from Word then the code is similar, the LatestFile function gets the latest file and the code line
.Attachments.Add LatestFile("C:\path\folder\")
adds it to the message. Change "C:\path\folder" to the actual folder you wish to get the latest file from.
The function must be in the same module as your macro.
As you have not listed your macro code, I have created a simpe macro to create a message. The macro needs to start Outlook. To do that I recommend that you download the code from the link in the macro and copy it to a new module in the same project, to ensure that Outlook is started correctly.
Sub Create_HTML_Mail()
'Requires the code - http://www.rondebruin.nl/win/s1/outlook/openclose.htm
'to either retrieve an open instance of Outlook or open Outlook if it is closed.
Dim olApp As Object
Dim oMail As Object
Set olApp = OutlookApp()
Set oMail = olApp.CreateItem(0)
With oMail
.BodyFormat = 2
.To = "someone@somewhere.com"
.Subject = "This is the subject"
.Attachments.Add LatestFile("C:\path\folder\")
.Display
End With
lbl_Exit:
Set oMail = Nothing
Set olApp = Nothing
Exit Sub
End Sub
Private Function LatestFile(strFolder As String, _
Optional strFilespec As String = "*.*") As String
Dim strName As String
Dim strRecent As String
Dim dDate As Date
Do Until Right(strFolder, 1) = Chr(92)
strFolder = strFolder & Chr(92)
Loop
strName = Dir(strFolder & strFilespec)
If strName <> "" Then
strRecent = strName
dDate = FileDateTime(strFolder & strName)
Do While strName <> ""
If FileDateTime(strFolder & strName) > dDate Then
strRecent = strName
dDate = FileDateTime(strFolder & strName)
End If
strName = Dir
Loop
End If
LatestFile = strFolder & strRecent
End Function