2017-10-13 3 views
1

J'ai un code vba qui envoie automatiquement des e-mails lorsqu'une date d'échéance approche d'au moins 7 sept jours à compter de la date actuelle. Le problème est qu'ils quand l'email est envoyé sans ma signature de perspectives. J'utilise Outlook 2016. Ce serait une grande aide pour moi si vous pouviez m'aider avec ceci.VBA, Insérer une signature Outlook dans le code vba

Le code est:

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 

Merci!

+1

double possible de [Comment ajouter défaut signature dans Outlook] (https://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook) – niton

Répondre

1

Ce que j'ai trouvé utile était de faire un HTMLBody. donc cette partie:

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 

ressemblerait

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 

Vous pourriez avoir besoin pour passer des événements, pas sûr que je ne l'ai pas testé avec Déactivé

+0

Ceci est faux - vous ne pouvez pas concaténer 2 documents HTML et produire un document HTML valide - votre les données doivent être insérées dans le corps HTML à l'endroit approprié. –

+0

Cela fonctionne, mais peut-être que j'ai frappé la chance en utilisant cela pendant un an ou plus ou est-ce que je manque quelque chose dans le «corps». Trouvé l'inspiration de https://www.rondebruin.nl/win/s1/outlook/signature.htm – krib

+0

Il fonctionne à ce lien parce que les données en cours d'ajout n'est pas un document HTML complet avec les balises html et head. Dans votre cas, vous ajoutez des données avant le début du document HTML valide. Si Outlook peut analyser cela, vous êtes chanceux. Généralement, ce n'est pas le cas. –