Building custom solutions that extend, automate, and integrate Microsoft 365 apps.
Code not giving expected results
Devon Nullman
21
Reputation points
Code:
Imports Microsoft.Office.Interop.Outlook
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim oApp As New Application
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim RootFolder As MAPIFolder = oNS.DefaultStore.GetRootFolder
For Each MFolder As Microsoft.Office.Interop.Outlook.Folder In RootFolder.Folders
Try
If MFolder.DefaultItemType = OlItemType.olMailItem Then
Dim MBItems As Items = MFolder.Items
For Each EMailitem As MailItem In MBItems
Dim Atchmnts As Attachments = EMailitem.Attachments
If Atchmnts.Count > 0 Then
TextBox1.AppendText("Folder: " & MFolder.Name & vbNewLine)
TextBox1.AppendText("From: " & EMailitem.SenderName & vbNewLine)
TextBox1.AppendText("Subj: " & EMailitem.Subject & vbNewLine)
TextBox1.AppendText(Atchmnts.Count.ToString & " Attachment(s):" & vbNewLine)
For Each a As Microsoft.Office.Interop.Outlook.Attachment In Atchmnts
TextBox1.AppendText(vbTab & a.FileName & " - " & a.Size.ToString & " bytes" & vbNewLine)
Next
TextBox1.AppendText(vbNewLine)
End If
Next
End If
Catch
TextBox1.AppendText("Error Processing " & vbNewLine)
End Try
Next
TextBox1.AppendText("Finished")
oApp.Quit()
oApp = Nothing
oNS = Nothing
End Sub
End Class
One result:
Folder: Inbox
From: Maria xxxxxxxxxxxxx
Subj: RE: Sewer Drawing
3 Attachment(s):
image001.png - 6561 bytes (embedded logo, not a real attachment)
image002
38883.tif - 1052020 bytes (actual attached file)
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
Outlook | Windows | Classic Outlook for Windows | For business
Using classic Outlook for Windows in business environments
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Processes in Microsoft 365 for setting up Office apps, redeeming product keys, and activating licenses.
Developer technologies | VB
Developer technologies | VB
An object-oriented programming language developed by Microsoft that can be used in .NET.
Sign in to answer