email versturen via Outlook met Handtekening

Status
Niet open voor verdere reacties.

Rene71

Gebruiker
Lid geworden
2 aug 2012
Berichten
133
ik gebruik onderstaande code om een pdf te versturen
maar nu wil ik ook automatisch er een handtekening bij zetten
maar zoals ik het doe krijg ik een foutmelding bij

Signature = oEmailItem.HTMLBody
compileerfout een variabele is niet gedefinieerd

wat doe ik niet goed ?

Code:
Private Sub Knop38_Click()
Dim folder As String
Dim FileName As String
Dim FilePath As String
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem

On Error GoTo Opslaan_ReportOpslaan
folder = CurrentProject.Path & "\TMP_PDF\"
MkDir folder
    
    Resume Opslaan_ReportOpslaan
Opslaan_ReportOpslaan:
FileName = "Contractnr " & Me.ContractID
FilePath = folder & FileName & ".pdf"
'maak tijdelijk bestand
DoCmd.OutputTo acOutputReport, "rptReport", acFormatPDF, FilePath
Set oOutlook = GetObject(, "Outlook.Application")
If oOutlook Is Nothing Then
Set oOutlook = New Outlook.Application
End If
Set oEmailItem = oOutlook.CreateItem(olMailItem)
With oEmailItem
.Display
End With
Signature = oEmailItem.HTMLBody
With oEmailItem
    .To = Me.E_Mail
    .CC = ""
    .BCC = ""
    .Subject = "Contract: " & Me.ContractID
    .Attachments.Add FilePath
    '.Body = "het contract " & Me.ContractID & " is bijgevoegd."
    '.BodyFormat = olFormatHTML
    .HTMLBody = "het contract " & Me.ContractID & " is bijgevoegd." & vbNewLine & vbc & Signature
    .Display
End With
Set oEmailItem = Nothing
Set oOutlook = Nothing
'verwijder het tijdelijke bestand
Kill FilePath
End Sub
 
Ik denk dat je een fout je maakt in je code.
Code:
    Set outApp = GetObject(, "Outlook.Application")
    If outApp Is Nothing Then Set outApp = New Outlook.Application
    Set oEmailItem = outApp.CreateItem(olMailItem)
    With oEmailItem
        .To = Me.E_Mail
        .CC = ""
        .BCC = ""
        .Subject = "Contract: " & Me.ContractID
        .Attachments.Add FilePath
        .BodyFormat = olFormatHTML
       .HTMLBody = "het contract " & Me.ContractID & " is bijgevoegd." & vbNewLine & vbNewLine & .HTMLBody
        .Display
    End With
 
de fout is eruit zo ook de regel Signature = oEmailItem.HTMLBody

kan je met helpen Michel om mijn outlook handtekening in de mail te krijgen
daar werd (door de fout, compileerfout een variabele is niet gedefinieerd)/ wordt niet naar verwezen in de code
ik heb er een testdB bij gedaan

Code:
Private Sub Knop38_Click()
Dim folder As String
Dim FileName As String
Dim FilePath As String
Dim outApp As Outlook.Application
Dim oEmailItem As MailItem

On Error GoTo Opslaan_ReportOpslaan
folder = CurrentProject.Path & "\TMP_PDF\"
MkDir folder
    
    Resume Opslaan_ReportOpslaan
Opslaan_ReportOpslaan:
FileName = "Contractnr " & Me.ContractID
FilePath = folder & FileName & ".pdf"

'maak tijdelijk bestand
DoCmd.OutputTo acOutputReport, "rptReport", acFormatPDF, FilePath
Set outApp = GetObject(, "Outlook.Application")
    If outApp Is Nothing Then Set outApp = New Outlook.Application
    Set oEmailItem = outApp.CreateItem(olMailItem)
 With oEmailItem
   'End With
  'Signature = oEmailItem.HTMLBody
   
        .To = Me.E_Mail
        .CC = ""
        .BCC = ""
        .Subject = "Contract: " & Me.ContractID
        .Attachments.Add FilePath
        .BodyFormat = olFormatHTML
       '.HTMLBody = "This is example of sending email with system signature" & vbNewLine & vbc & Signature
      .HTMLBody = "het contract " & Me.ContractID & " is bijgevoegd." & vbNewLine & vbNewLine & .HTMLBody
        .Display
    End With
Set oEmailItem = Nothing
Set outApp = Nothing
'verwijder het tijdelijke bestand
Kill FilePath
End Sub
 

Bijlagen

Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan