Koe: hieronder de code die ik momenteel gebruik
Sub Dotch()
''variabelen
Plaats = "C:\JVC\Contracten\" ''AANPASSEN indien nodig (standaard: "C:\JVC\Contracten\")
Naam = Range("Q1").Value
adres = Range("O11").Value
CC = Range("R14").Value
BCC = Range("R15").Value
onderwerp = "Contract"
ondergetekende = Range("C41").Value
handtekening = "Beste," & vbLf _
& vbLf _
& vbLf _
& "Met vriendelijke groeten," & vbLf _
& "Ann"
''Nagaan of het bestand reeds bestaat, zoniet opslaan en verder
If Dir(Plaats & Naam & ".pdf") <> "" Then
MsgBox "Het contract - " & Naam & ".pdf - bestaat reeds. Vul een ander contractnummer in of wis het bestaande contract"
Exit Sub
Else
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Plaats & Naam & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=False
End If
''bestand toevoegen aan mail met naam vermeld in cel Q1
verder:
Bestand = ThisWorkbook.Path & "\" & Range("Q1").Value & ".pdf" ''= variabele
HHR = "C:\JVC\HHR.pdf" ''AANPASSEN indien nodig
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Bestand
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = adres
.CC = CC
.BCC = BCC
.Subject = onderwerp
.Body = handtekening & vbNewLine & ondergetekende
.Attachments.Add Bestand
.Attachments.Add HHR
.Display
End With
Kill (Bestand)
End Sub