Olá, nao tenho muito conhecimento em vba mas gostaria da ajuda de vocês, preciso desenvolver um macro, onde ele pega o endereco de email(outlook) do remetente, verifica esse endereço no banco de dados access, e salva os anexos do email renomeandos conforme o codigo salvo no banco de dados desse remetente, poderiam me ajudar com isso, tenho o macro onde ele salva os anexos dos emails selecionados, mas com o nome original do arquivo, segue o macro,
Public Sub AttachmentIndex()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
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
Dim sAppName As String
Dim sSection As String
Dim sKey As String
Dim lRegValue As Long
Dim lFormValue As Long
Dim iDefault As Integer
sAppName = "Outlook"
sSection = "Index"
sKey = "Last Index Number"
iDefault = 10000
lRegValue = GetSetting(sAppName, sSection, sKey, iDefault)
If lRegValue = 0 Then lRegValue = iDefault
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next
Set objOL = Application
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = "C:TempAnexosOutlook"
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
Atmt.SaveAsFile FileName
lcount = InStrRev(strFile, ".") - 1
pre = Left(strFile, lcount)
ext = Right(strFile, Len(strFile) - lcount)
strFile = strFolderpath & pre & "_" & lRegValue & ext
objAttachments.Item(i).SaveAsFile strFile
lRegValue = lRegValue + 1
Err.Clear
Next
SaveSetting sAppName, sSection, sKey, lRegValue
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
Postado : 04/10/2019 12:53 pm