outlook VBA salva anexo no disco rígido em uma pasta específica diferente de 'my documents folder'

0

Encontrei uma macro que salva um anexo de um e-mail no Outlook e, nesse aspecto, funciona muito bem, mas salva na pasta "meu documento"

Eu gostaria que ele salva em outra pasta que tem um caminho completamente diferente, no entanto eu tenho problemas para ver como o código que faz isso funciona e, portanto, eu não tenho sucesso em modificá-lo

O caminho atual da pasta de documentos é C: \ Usuários \ me \ Documents \ OLAttachments mas deve ser Y: \ work_network \ me \ outlook-file

O código atual que eu tenho é

Public Sub SaveAttachments()

Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String

' Get the path to your My Documents folder
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next

' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")

' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection

' Set the Attachment folder.
strFolderpath = strFolderpath & "\OLAttachments\"

' Check each selected item for attachments.
For Each objMsg In objSelection

Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count

If lngCount > 0 Then
For i = lngCount To 1 Step -1

' Get the file name.
strFile = Left(objAttachments.Item(i).FileName, Len(stry) - 4) & Format(Date, "DDMMYY") & ".xls"

' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile

' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile

Next i
End If

Next

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

Eu não entendo como essa linha funciona

strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)

E eu tenho problemas para adaptá-lo ao que eu preciso.

Alguém pode fornecer alguma ajuda sobre isso? Muito obrigado

    
por ploom 25.08.2016 / 15:45

1 resposta

1

A linha mencionada obtém o caminho para a pasta especial "Meus documentos". Você só precisa substituir esta linha com:

strFolderpath = "Y:\work_network\me\outlook-file\"

e remova completamente esta linha:

strFolderpath = strFolderpath & "\OLAttachments\"
    
por 25.08.2016 / 16:22