Guest User

slamkode

a guest
Jul 8th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.48 KB | None | 0 0
  1. Sub create_and_add_to()
  2.     On Error Resume Next
  3.     Dim OutApp As Object
  4.     Dim OutMail As Object
  5.     Dim objNsp As Object
  6.     Dim colSyc As Object
  7.     Dim objSyc As Object
  8.     Dim i As Integer
  9.     Dim ActSheet As Worksheet
  10.     Dim SelRange As Range
  11.     Dim toAddress As String
  12.     Dim signature As String
  13.    
  14.        
  15.     Set ActSheet = ActiveSheet
  16.     Set SelRange = Selection
  17.  
  18.     Set OutApp = CreateObject("Outlook.Application")
  19.     Set OutMail = OutApp.CreateItem(0)
  20.     Set objNsp = appOL.Application.GetNamespace("MAPI")
  21.     Set colSyc = objNsp.SyncObjects
  22.  
  23.     'On Error Resume Next
  24.      
  25.     For Each cell In Selection
  26.         If cell.Column = 4 Then
  27.             toAddress = toAddress & cell & ";"
  28.         Else
  29.             ccAddress = ccAddress & ";" & cell & ";"
  30.         End If
  31.     Next cell
  32.     signature = OutApp.body
  33.     With OutMail
  34.         .To = toAddress
  35.         .Subject = ""
  36.         '.body = "" & vbNewLine & signature
  37.         .CC = ccAddress
  38.         '.Attachments.Add BFld1 & TBFileName.Text
  39.         '.Send ' to send in background
  40.          .Display ' to open a mail window with a normal 'SEND' icon available
  41.          .ActiveWindow.Activate
  42.     End With
  43.  
  44.     For i = 1 To colSyc.Count
  45.         Set objSyc = colSyc.Item(i)
  46.         objSyc.Start
  47.     Next
  48.  
  49.     On Error GoTo 0
  50.  
  51.     'OutApp.Quit
  52.  
  53.     Set OutMail = Nothing
  54.     Set objNsp = Nothing
  55.     Set colSyc = Nothing
  56.     Set objSyc = Nothing
  57.     Set OutApp = Nothing
  58.  
  59. aa:
  60. End Sub
Advertisement
Add Comment
Please, Sign In to add comment