PDA

View Full Version : Codigo VBA para fecha matar o arquivo temporário.



LLEAL
12-28-2016, 04:32 PM
Boa noite galera.
tenho um código abaixo que salva os arquivos em PDF e XLS e em seguida anexa no corpo do e-mail e depois envia automático, porem fica aberto o arquivo que foi enviado com o nome salvo... Eu gostaria de ajuda para fazer todo esse processo, porém fecha esse arquivo e abra o arquivo original novamente.
Veja o código abaixo...

Private Sub PDF_Mail_Click()
Dim nome As String
Dim arquivo As String
Dim endereco As String
Dim endereco1 As String
'NA CELULA "A2" SÃO OS ENDEREÇOS DE EMAIL DOS DESTINATÁRIOS
endereco = "" & ";" & " " & Range("A2").Value
'endereco1 = "" & ";" & " " & Range("b41").Value
'É DIRETÓRIO ONDE SERÁ SALVO O ARQUIVO COM NOME E DATA FORMATO PDF'
nome = "C:\Users\luiz.leal\Desktop\Envase\Arquivos_PDF\" & "" & Range("A1").Value & ".pdf"
arquivo = "C:\Users\luiz.leal\Desktop\Envase\Arquivos_PDF\" & [a1].Value & ".xls"


ActiveWorkbook.SaveAs Filename:=arquivo
ActiveSheet.Range("A3:U83").ExportAsFixedFormat Type:=xlTypePDF, Filename:=nome




Set myActiveSheet = CreateObject("Outlook.Application")
Set objmail = myActiveSheet.CreateItem(olMailItem)
Set myattachments = objmail.attachments


With objmail
.To = endereco
'.CC = endereco1
.Subject = "Controle de Envase" & " - " & Range("H5").Value & " - " & Range("H7").Value & " - " & Range("j7").Value & " - " & Range("c7").Value
myattachments.Add nome
myattachments.Add arquivo
'.BodyFormat = olFormatHTML
.HTMLBody = "<html><body></br>Segue em anexo o Controle de Envase do PRD 03.008<br></body></html>" & "<html><body></br> Qualquer dúvida contate à equipe!<br></body></html>"
.Display
.Send
MsgBox ("E-mail enviado com sucesso!")
End With


'Deleta o arquivo temporário
wbAtual.ChangeFileAccess Mode:=xlReadOnly
Kill wbAtual.FullName
wbAtual.Close SaveChanges:=False


Set MailOutLook = Nothing
End Sub