Compartilhar via


Método Attachment.SaveAsFile (Outlook)

Salva o anexo no caminho especificado.

Sintaxe

expression. SaveAsFile( _Path_ )

Expressão Uma variável que representa um objeto Attachment .

Parâmetros

Nome Obrigatório/Opcional Tipo de dados Descrição
Path Obrigatório String O local em que o anexo será salvo.

Exemplo

Este exemplo Visual Basic for Applications (VBA) usa o método SaveAsFile para salvar o primeiro anexo do item aberto no momento como um arquivo na pasta Documents, usando o nome de exibição do anexo como o nome de arquivo.

Sub SaveAttachment() 
 
 Dim myInspector As Outlook.Inspector 
 
 Dim myItem As Outlook.MailItem 
 
 Dim myAttachments As Outlook.Attachments 
 
 
 
 Set myInspector = Application.ActiveInspector 
 
 If Not TypeName(myInspector) = "Nothing" Then 
 
 If TypeName(myInspector.CurrentItem) = "MailItem" Then 
 
 Set myItem = myInspector.CurrentItem 
 
 Set myAttachments = myItem.Attachments 
 
 'Prompt the user for confirmation 
 
 Dim strPrompt As String 
 
 strPrompt = "Are you sure you want to save the first attachment in the current item to the Documents folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file." 
 
 If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then 
 
 myAttachments.Item(1).SaveAsFile Environ("HOMEPATH") & "\My Documents\" & _ 
 
 myAttachments.Item(1).DisplayName 
 
 End If 
 
 Else 
 
 MsgBox "The item is of the wrong type." 
 
 End If 
 
 End If 
 
End Sub

Confira também

Objeto Attachment

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.