Advertisement
Guest User

all trick world - Tips

a guest
Jun 24th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.50 KB | None | 0 0
  1.  
  2. 'Specify the path where your files are present(.xls,.doc,.pdf etc)
  3. strPath="C:\Test\"
  4.  
  5. Set objFso = CreateObject("Scripting.FileSystemObject")
  6. Set objFolder = objFso.GetFolder (strPath)
  7. Set objExcel= CreateObject("Excel.Application")
  8. objExcel.Visible= False
  9.  
  10. 'This section of code will attach pdf file present in the Test folder
  11.  
  12. For Each objFile In objFolder.Files
  13.     If objFso.GetExtensionName(objFile.Path) = "pdf" Then
  14.        
  15.     Set MyApp = CreateObject("Outlook.Application")
  16.     Set MyItem = MyApp.CreateItem(0) 'olMailItem
  17.     With MyItem
  18.         .To = "c2praveen30jun@gmail.com"
  19.         .Subject = "How to send attached file automatically"
  20.         .ReadReceiptRequested = False
  21.         .HTMLBody = "<b>Put your mesage here.</b>"
  22.         .Attachments.Add objFolder.Path & "\" & objFso.GetFileName(objFile.path)
  23.     End With
  24.     MyItem.Display
  25.     End if
  26. Next   
  27.  
  28. 'This section of code will attach xls  file present in the subfolder of the Test folder
  29.  
  30. For Each objFolder In objFolder.SubFolders
  31.       For Each objFile In objFolder.Files
  32.  
  33.     If objFso.GetExtensionName(objFile.Path) = "xls" Then
  34.    
  35.     Set MyApp = CreateObject("Outlook.Application")
  36.     Set MyItem = MyApp.CreateItem(0) 'olMailItem
  37.     With MyItem
  38.         .To = "c2praveen30jun@gmail.com"
  39.         .Subject = "How to send attached file automatically"
  40.         .ReadReceiptRequested = False
  41.  
  42.         .HTMLBody = "<b>Put your mesage here.</b>"
  43.  
  44.                          
  45.  
  46.  
  47.         .Attachments.Add objFolder.Path & "\" & objFso.GetFileName(objFile.path)
  48.     End With
  49.     MyItem.Display
  50.     End if
  51.       Next
  52. Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement