Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Specify the path where your files are present(.xls,.doc,.pdf etc)
- strPath="C:\Test\"
- Set objFso = CreateObject("Scripting.FileSystemObject")
- Set objFolder = objFso.GetFolder (strPath)
- Set objExcel= CreateObject("Excel.Application")
- objExcel.Visible= False
- 'This section of code will attach pdf file present in the Test folder
- For Each objFile In objFolder.Files
- If objFso.GetExtensionName(objFile.Path) = "pdf" Then
- Set MyApp = CreateObject("Outlook.Application")
- Set MyItem = MyApp.CreateItem(0) 'olMailItem
- With MyItem
- .To = "c2praveen30jun@gmail.com"
- .Subject = "How to send attached file automatically"
- .ReadReceiptRequested = False
- .HTMLBody = "<b>Put your mesage here.</b>"
- .Attachments.Add objFolder.Path & "\" & objFso.GetFileName(objFile.path)
- End With
- MyItem.Display
- End if
- Next
- 'This section of code will attach xls file present in the subfolder of the Test folder
- For Each objFolder In objFolder.SubFolders
- For Each objFile In objFolder.Files
- If objFso.GetExtensionName(objFile.Path) = "xls" Then
- Set MyApp = CreateObject("Outlook.Application")
- Set MyItem = MyApp.CreateItem(0) 'olMailItem
- With MyItem
- .To = "c2praveen30jun@gmail.com"
- .Subject = "How to send attached file automatically"
- .ReadReceiptRequested = False
- .HTMLBody = "<b>Put your mesage here.</b>"
- .Attachments.Add objFolder.Path & "\" & objFso.GetFileName(objFile.path)
- End With
- MyItem.Display
- End if
- Next
- Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement