home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form AutoMessageForm
- Caption = "VBA DEMO: E-Message Automation"
- ClientHeight = 6405
- ClientLeft = 60
- ClientTop = 375
- ClientWidth = 11850
- LinkTopic = "Form1"
- ScaleHeight = 6405
- ScaleWidth = 11850
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command3
- Caption = "Create && Send"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 480
- Left = 9390
- TabIndex = 6
- Top = 5865
- Width = 2355
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 5265
- Left = 5580
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 5
- Text = "MssgForm.frx":0000
- Top = 435
- Width = 6165
- End
- Begin VB.ListBox List3
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 2370
- Left = 120
- Sorted = -1 'True
- TabIndex = 4
- Top = 3330
- Width = 5340
- End
- Begin VB.ListBox List2
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 2370
- Left = 2850
- Sorted = -1 'True
- TabIndex = 1
- Top = 435
- Width = 2610
- End
- Begin VB.ListBox List1
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 2370
- Left = 135
- TabIndex = 0
- Top = 435
- Width = 2580
- End
- Begin VB.Label Label3
- Caption = "Recipients"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 150
- TabIndex = 8
- Top = 3030
- Width = 2580
- End
- Begin VB.Label Label2
- Alignment = 2 'Center
- Caption = "Message Text"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 5610
- TabIndex = 7
- Top = 135
- Width = 6105
- End
- Begin VB.Label Label5
- Caption = "Contacts"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 2820
- TabIndex = 3
- Top = 135
- Width = 2670
- End
- Begin VB.Label Label1
- Caption = "Companies"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 135
- TabIndex = 2
- Top = 90
- Width = 2580
- End
- Attribute VB_Name = "AutoMessageForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' ******************************
- ' ******************************
- ' ** MASTERING VB6 **
- ' ** by Evangelos Petroutos **
- ' ** SYBEX, 1998 **
- ' ******************************
- ' ******************************
- Dim OLApp As Application
- Dim mNameSpace As NameSpace
- Dim mFolder As MAPIFolder
- Dim mItem As MailItem
- Dim mContact As ContactItem
- Dim allContacts As Items
- Sub StartOutlook()
- On Error GoTo OutlookNotStarted
- Set OLApp = CreateObject("Outlook.Application")
- On Error GoTo NoMAPINameSpace
- Set mNameSpace = OLApp.GetNamespace("MAPI")
- List1.Clear
- List2.Clear
- Exit Sub
- OutlookNotStarted:
- MsgBox "Could not start Outlook"
- Exit Sub
- NoMAPINameSpace:
- MsgBox "Could not get MAPI NameSpace"
- Exit Sub
- End Sub
- Sub ReadContacts()
- Set allContacts = mNameSpace.GetDefaultFolder(olFolderContacts).Items
- allContacts.Sort "CompanyName"
- On Error Resume Next
- For Each mContact In allContacts
- If Trim(mContact.CompanyName) <> "" Then List1.AddItem mContact.CompanyName
- If List1.List(List1.NewIndex) = List1.List(List1.NewIndex - 1) Then List1.RemoveItem List1.NewIndex
- Next
- End Sub
- Private Sub Command3_Click()
- Dim thisMessage As MailItem
- Dim strMsg As String
- strMsg = Text1.Text
- For i = 0 To List3.ListCount - 1
- Set thisMessage = OLApp.CreateItem(olMailItem)
- With thisMessage
- strMsg = Replace(strMsg, "<<NAME>>", List3.List(i))
- .Recipients.Add List3.List(i)
- .Subject = "News from Sybex " & Format(Date, vbLongDate)
- .Body = strMsg
- .Send
- End With
- Next
- End Sub
- Private Sub Form_Load()
- StartOutlook
- ReadContacts
- End Sub
- Private Sub List1_Click()
- Dim CompanyName As String
- Dim filterString As String
- Dim thisContact As ContactItem
- If List1.ListIndex = -1 Then Exit Sub
- CompanyName = List1.Text
- filterString = "[CompanyName] = """ & CompanyName & """"
-
- Set thisContact = allContacts.Find(filterString)
- If IsNull(thisContact) Then
- MsgBox "Fatal error in locating a contact. Program will exit"
- End
- End If
- List2.Clear
- While Not thisContact Is Nothing
- If Trim(thisContact.FullName) <> "" Then List2.AddItem thisContact.FullName
- Set thisContact = allContacts.FindNext
- Wend
- End Sub
- Private Sub List2_Click()
- Dim ContactName As String
- Dim filterString As String
- If List2.ListIndex = -1 Then Exit Sub
- ContactName = List2.Text
- filterString = "[FullName] = """ & ContactName & """"
-
- Set thisContact = allContacts.Find(filterString)
- If IsNull(thisContact) Then
- MsgBox "Fatal error in locating a contact's name. Program will exit"
- End
- End If
- End Sub
- Private Sub List2_DblClick()
- If List2.ListIndex >= 0 Then
- List3.AddItem List2.Text
- End If
- End Sub
-