Results 1 to 21 of 21

Thread: vs 2003 and outlook?

Threaded View

  1. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: vs 2003 and outlook?

    Ok, I did my part now its up to you
    VB Code:
    1. Option Explicit On
    2.  
    3. 'Add a reference to MS Outlook xx.0 Object Library
    4. 'Project > Add Reference... > COM tab > select MS Outlook 11.0 Object library
    5. Imports Microsoft.Office.Interop
    6.  
    7. Public Class Form1
    8.  
    9.     Inherits System.Windows.Forms.Form
    10.  
    11. #Region " Outlook Variables "
    12.     Private moApp As Outlook.Application
    13.     Private moNS As Outlook.NameSpace
    14.     Private moFolder As Outlook.MAPIFolder
    15.     Private mbTerminate As Boolean
    16. #End Region
    17.  
    18. #Region " Outlook Constants "
    19.     Private Const olMail = 43
    20.     Private Const olFormatUnspecified = 0
    21.     Private Const olFormatPlain = 1
    22.     Private Const olFormatHTML = 2
    23.     Private Const olFormatRichText = 3
    24. #End Region
    25.  
    26. #Region " Windows Form Designer generated code "
    27.  
    28.     Public Sub New()
    29.         MyBase.New()
    30.  
    31.         'This call is required by the Windows Form Designer.
    32.         InitializeComponent()
    33.  
    34.         'Add any initialization after the InitializeComponent() call
    35.  
    36.     End Sub
    37.  
    38.     'Form overrides dispose to clean up the component list.
    39.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    40.         If disposing Then
    41.             If Not (components Is Nothing) Then
    42.                 components.Dispose()
    43.             End If
    44.         End If
    45.         MyBase.Dispose(disposing)
    46.     End Sub
    47.  
    48.     'Required by the Windows Form Designer
    49.     Private components As System.ComponentModel.IContainer
    50.  
    51.     'NOTE: The following procedure is required by the Windows Form Designer
    52.     'It can be modified using the Windows Form Designer.  
    53.     'Do not modify it using the code editor.
    54.     Friend WithEvents btnClose As System.Windows.Forms.Button
    55.     Friend WithEvents btnBrowse As System.Windows.Forms.Button
    56.     Friend WithEvents txtFolderPath As System.Windows.Forms.TextBox
    57.     Friend WithEvents lblFolderPath As System.Windows.Forms.Label
    58.     Friend WithEvents btnParse As System.Windows.Forms.Button
    59.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    60.         Me.btnClose = New System.Windows.Forms.Button
    61.         Me.btnBrowse = New System.Windows.Forms.Button
    62.         Me.txtFolderPath = New System.Windows.Forms.TextBox
    63.         Me.lblFolderPath = New System.Windows.Forms.Label
    64.         Me.btnParse = New System.Windows.Forms.Button
    65.         Me.SuspendLayout()
    66.         '
    67.         'btnClose
    68.         '
    69.         Me.btnClose.Location = New System.Drawing.Point(208, 96)
    70.         Me.btnClose.Name = "btnClose"
    71.         Me.btnClose.TabIndex = 0
    72.         Me.btnClose.Text = "&Close"
    73.         '
    74.         'btnBrowse
    75.         '
    76.         Me.btnBrowse.Location = New System.Drawing.Point(264, 40)
    77.         Me.btnBrowse.Name = "btnBrowse"
    78.         Me.btnBrowse.Size = New System.Drawing.Size(20, 20)
    79.         Me.btnBrowse.TabIndex = 1
    80.         Me.btnBrowse.Text = "..."
    81.         '
    82.         'txtFolderPath
    83.         '
    84.         Me.txtFolderPath.Location = New System.Drawing.Point(16, 40)
    85.         Me.txtFolderPath.Name = "txtFolderPath"
    86.         Me.txtFolderPath.Size = New System.Drawing.Size(248, 20)
    87.         Me.txtFolderPath.TabIndex = 2
    88.         Me.txtFolderPath.Text = ""
    89.         '
    90.         'lblFolderPath
    91.         '
    92.         Me.lblFolderPath.Location = New System.Drawing.Point(16, 24)
    93.         Me.lblFolderPath.Name = "lblFolderPath"
    94.         Me.lblFolderPath.Size = New System.Drawing.Size(100, 16)
    95.         Me.lblFolderPath.TabIndex = 3
    96.         Me.lblFolderPath.Text = "Folder Path:"
    97.         '
    98.         'btnParse
    99.         '
    100.         Me.btnParse.Location = New System.Drawing.Point(124, 96)
    101.         Me.btnParse.Name = "btnParse"
    102.         Me.btnParse.TabIndex = 4
    103.         Me.btnParse.Text = "Parse Links"
    104.         '
    105.         'Form1
    106.         '
    107.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    108.         Me.ClientSize = New System.Drawing.Size(292, 126)
    109.         Me.Controls.Add(Me.btnParse)
    110.         Me.Controls.Add(Me.lblFolderPath)
    111.         Me.Controls.Add(Me.txtFolderPath)
    112.         Me.Controls.Add(Me.btnBrowse)
    113.         Me.Controls.Add(Me.btnClose)
    114.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    115.         Me.MaximizeBox = False
    116.         Me.Name = "Form1"
    117.         Me.Text = "Outlook Link Parser™"
    118.         Me.ResumeLayout(False)
    119.  
    120.     End Sub
    121.  
    122. #End Region
    123.  
    124.     Private Sub btnParse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParse.Click
    125.         Dim oEmail As Outlook.MailItem
    126.         Dim i As Integer
    127.         For i = 1 To moFolder.Items.Count
    128.             'Check for mailitems only and not undeliverable errors, meeting requests, or other non-mail items.
    129.             If moFolder.Items(i).Class = olMail Then
    130.                 oEmail = moFolder.Items.Item(i)
    131.                 'Check for body format type
    132.                 Select Case oEmail.BodyFormat
    133.                     Case Outlook.OlBodyFormat.olFormatUnspecified
    134.                         'Try to parse using plain text format?
    135.  
    136.                     Case Outlook.OlBodyFormat.olFormatPlain
    137.                         'Try to parse text
    138.                         If oEmail.Body.IndexOf("http://www.vbforums.com") > 0 Then
    139.                             Console.WriteLine(oEmail.Body.Substring(oEmail.Body.IndexOf("http://www.vbforums.com"), 23))
    140.                         End If
    141.                     Case Outlook.OlBodyFormat.olFormatHTML
    142.                         'Try to parse html
    143.                         If oEmail.HTMLBody.IndexOf("http://www.vbforums.com") > 0 Then
    144.                             'Do other stuff
    145.                             '...
    146.                         End If
    147.                     Case Outlook.OlBodyFormat.olFormatRichText
    148.                         'Try to parse RTF
    149.  
    150.                 End Select
    151.                 oEmail = Nothing
    152.             End If
    153.         Next
    154.         oEmail = Nothing
    155.         Me.Activate()
    156.         MessageBox.Show("Done!", "Outlook Link Parser™", MessageBoxButtons.OK, MessageBoxIcon.Information)
    157.     End Sub
    158.  
    159.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    160.         mbTerminate = False
    161.         moApp = GetObject(, "Outlook.Application")
    162.         If moApp Is Nothing Then
    163.             moApp = New Outlook.Application
    164.             mbTerminate = True
    165.         End If
    166.         moNS = moApp.GetNamespace("MAPI")
    167.     End Sub
    168.  
    169.     Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
    170.         moFolder = moNS.PickFolder
    171.         If Not moFolder Is Nothing Then
    172.             txtFolderPath.Text = moFolder.FolderPath
    173.         End If
    174.         Me.Activate()
    175.     End Sub
    176.  
    177.     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    178.         Me.Dispose()
    179.     End Sub
    180.  
    181.     Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    182.         moFolder = Nothing
    183.         moNS = Nothing
    184.         If Not (moApp Is Nothing) And (mbTerminate = True) Then
    185.             moApp.Quit()
    186.         End If
    187.         moApp = Nothing
    188.     End Sub
    189.  
    190. End Class
    Last edited by RobDog888; Apr 19th, 2005 at 03:51 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width