2017-10-13 3 views
1

현재 날짜보다 최소 7 일 전에 만기일이되면 자동으로 이메일을 보내는 vba 코드가 있습니다. 문제는 전자 메일이 Outlook 서명없이 전송되는 경우입니다. 나는 전망 2016을 사용한다. 나를 도와 줄 수 있다면 큰 도움이 될 것이다.VBA, VBA 코드에 Outlook 서명 삽입

코드는 다음과 같습니다

Sub email() 
Dim lRow As Integer 
Dim i As Integer 
Dim toDate As Date 
Dim toList As String 
Dim eSubject As String 
Dim eBody As String 

With Application 
    .ScreenUpdating = False 
    .EnableEvents = False 
    .DisplayAlerts = False 
End With 

Sheets(1).Select 
lRow = Cells(Rows.Count, 4).End(xlUp).Row 

For i = 2 To lRow 
toDate = Cells(i, 3) 
If toDate - Date <= 7 Then 
    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

     toList = Cells(i, 4) 'gets the recipient from col D 
     eSubject = "Doukementacion per " & Cells(i, 2) & " Targa " & Cells(i, 5) 
     eBody = "Pershendetje Adjona" & vbCrLf & vbCrLf & "Perfundo dokumentacionin e nevojshem per " & Cells(i, 2) & " me targa " & Cells(i, 5) 

     On Error Resume Next 
     With OutMail 
     .To = toList 
     .CC = "" 
     .BCC = "" 
     .Subject = eSubject 
     .Body = eBody 
     .bodyformat = 1 
     '.Display ' ********* Creates draft emails. Comment this out when you are ready 
     .Send  '********** UN-comment this when you are ready to go live 
     End With 
    On Error GoTo 0 
    Set OutMail = Nothing 
    Set OutApp = Nothing 
Cells(i, 11) = "Mail Sent " & Date + Time 'Marks the row as "email sent in Column A" 
End If 
Next i 

ActiveWorkbook.Save 

With Application 
    .ScreenUpdating = True 
    .EnableEvents = True 
    .DisplayAlerts = True 
End With 
End Sub 

감사합니다!

+1

가능한 복제를 비활성화 이벤트와 테스트하지 않았기 때문에 당신은 확실하지가 이벤트를 전환해야 할 수도 있습니다

With OutMail .Display 'ads the signature .To = toList .Subject = eSubject .HTMLBody = eBody & .HTMLBody '.Display ' ********* Creates draft emails. Comment this out when you are ready .Send '********** UN-comment this when you are ready to go live End With 

과 같을 것이다 [기본을 추가하는 방법 Sign in Outlook] (https://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook) – niton

답변

1

도움이되는 것으로 알고있는 것은 HTMLBody입니다. 그래서이 부분은 :

With OutMail 
    .To = toList 
    .CC = "" 
    .BCC = "" 
    .Subject = eSubject 
    .Body = eBody 
    .bodyformat = 1 
    '.Display ' ********* Creates draft emails. Comment this out when you are ready 
    .Send  '********** UN-comment this when you are ready to go live 
End With 

내가의

+0

이것은 잘못된 것입니다. 두 개의 HTML 문서를 연결하여 유효한 HTML 문서를 생성 할 수 없습니다. 적절한 위치에서 HTML 본문에 데이터를 삽입해야합니다. –

+0

그것은 작동하지만, 1 년 정도 이것을 사용하여 운이 좋았거나, 내가 '몸'에서 뭔가를 놓친 것일 수도 있습니다. https://www.rondebruin.nl/win/s1/outlook/signature.htm에서 영감을 얻었습니다. – krib

+0

추가되는 데이터가 html 및 head 태그가있는 완전한 HTML 문서가 아니기 때문에 해당 링크에서 작동합니다. 귀하의 경우 유효한 HTML 문서가 시작되기 전에 데이터를 추가하고 있습니다. Outlook이이를 분석 할 수 있다면 운이 좋다. 일반적으로 그렇지 않습니다. –