Guest User

Untitled

a guest
Apr 27th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.42 KB | None | 0 0
  1. Dim Today, FolderName$, DateValue$, NameofFile$, FullFileName$
  2.    FolderName$ = "D:\Dagafsluitrapport\Wilrijk\" + DatePart('yyyy', Date) + "\\" + MonthName(Month(Date)) + "\\"
  3.    DateValue$ = Format(Now, "yy-mm-dd")
  4.    NameofFile$ = "dagafsluitrapport"
  5.    FullFileName$ = FolderName$ + DateValue$ + " " + NameofFile$
  6.    ActiveDocument.SaveAs FileName:=FullFileName$, FileFormat:=wdFormatDocument
  7.  
  8.  
  9. Dim bStarted As Boolean
  10. Dim oOutlookApp As Outlook.Application
  11. Dim oItem As Outlook.MailItem
  12. Dim ddate As Date
  13.  
  14. ddate = Date
  15.  
  16.  
  17. On Error Resume Next
  18.  
  19. If Len(ActiveDocument.Path) = 0 Then
  20.     MsgBox "Document needs to be saved first"
  21.     Exit Sub
  22. End If
  23.  
  24. Set oOutlookApp = GetObject(, "Outlook.Application")
  25. If Err <> 0 Then
  26.     Set oOutlookApp = CreateObject("Outlook.Application")
  27.     bStarted = True
  28. End If
  29.  
  30. Set oItem = oOutlookApp.CreateItem(olMailItem)
  31.  
  32. With oItem
  33.     .To = "[email protected]"
  34.     .Subject = "Dagrapport" + " " & ddate
  35.     'Add the document as an attachment, you can use the .displayname property
  36.     'to set the description that's used in the message
  37.     .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
  38.       DisplayName:="Document as attachment"
  39.     .Send
  40.    
  41.    
  42.    
  43. End With
  44.  
  45. ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
  46.  
  47.  
  48. If bStarted Then
  49.     oOutlookApp.Quit
  50. End If
  51.  
  52. Set oItem = Nothing
  53. Set oOutlookApp = Nothing
  54. Application.Quit
  55.  
  56. End Sub
Advertisement
Add Comment
Please, Sign In to add comment