Attachments Property

Microsoft Outlook Visual Basic

Show All

Attachments Property

       

Returns an Attachments object that represents all the attachments for the specified item.

expression.Attachments

expression   Required. An expression that returns one of the objects in the Applies To list.

Example

This Visual Basic for Applications example uses the Remove method to remove all attachments from a forwarded message before sending it on to John Y. Chen.

Set myOlApp = CreateObject("Outlook.Application")
Set myinspector = myOlApp.ActiveInspector
If Not TypeName(myinspector) = "Nothing" Then
      Set myitem = myinspector.CurrentItem.Forward
      Set myattachments = myitem.attachments
        If Not TypeName(myattachments) = "Nothing" Then
         While myattachments.Count > 0
             myattachments.Remove 1
         Wend
         myitem.Recipients.Add "John Y. Chen"
         myitem.Send
        End If
   MsgBox "The current item is not of the correct type"
Else
  MsgBox "There is no active Inspector"
End If

If you use VBScript, you do not create the Application object. This example shows how to perform the same task using VBScript.

Set myinspector = Application.ActiveInspector
If Not TypeName(myinspector) = "Nothing" Then
      Set myitem = myinspector.CurrentItem.Forward
      Set myattachments = myitem.attachments
        If Not TypeName(myattachments) = "Nothing" Then
         While myattachments.Count > 0
             myattachments.Remove 1
         Wend
         myitem.Recipients.Add "John Y. Chen"
         myitem.Send
        End If
   MsgBox "The current item is not of the correct type"
Else
  MsgBox "There is no active Inspector"
End If