excelnewbie2018
New Member
- Joined
- Jan 16, 2018
- Messages
- 8
Dear community, I want to create a Macro to check everyday if a new new file has been added to a specific folder and notify me per email. I have seen some codes to check if a certain file given a specific name exists but none of them really answers my question.
I came up with the following, which anyway gives me a message box but not an email.
Sub LookForNew()<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;"> Dim n As String, msg As String, d As Date
msg = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\TestFolder").Files
For Each fil In fils
n = fil.Name
d = fil.DateCreated
If d >= Date - 1 Then
msg = msg & n & vbTab & d & vbCrLf
End If
Next fil
If msg = "" Then
MsgBox "No new files"
Else
MsgBox msg
End If
Set fso = Nothing
End Sub</code>I have also thought about creating a list of directories but I do not know what macro I could use to detect any modification. Can anybody help me with this?
Thank you in advance!
I came up with the following, which anyway gives me a message box but not an email.
Sub LookForNew()<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;"> Dim n As String, msg As String, d As Date
msg = ""
Set fso = CreateObject("Scripting.FileSystemObject")
Set fils = fso.GetFolder("C:\TestFolder").Files
For Each fil In fils
n = fil.Name
d = fil.DateCreated
If d >= Date - 1 Then
msg = msg & n & vbTab & d & vbCrLf
End If
Next fil
If msg = "" Then
MsgBox "No new files"
Else
MsgBox msg
End If
Set fso = Nothing
End Sub</code>I have also thought about creating a list of directories but I do not know what macro I could use to detect any modification. Can anybody help me with this?
Thank you in advance!