Edmoor,
Het werkt idd, was het niet dat het de bedoeling is dat het document verzonden wordt als PDF file en niet als docx.
Het verzenden had ik al ingeregeld.
[ Private Sub CommandButton1_Click()
CommandButton1.Enabled = False
'CommandButton1.Caption = "VERZONDEN"
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
On Error Resume Next
' Controleren of Outlook gestart is
Set appOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
' Outlook is niet gestart
Set appOutlook = CreateObject("Outlook.Application")
bStart = True
End If
' Nieuw e-mailbericht maken
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.SaveAs "Kandidaat voor een bloemetje"
Const SaveRoot = "C:\Temp\"
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & "\"
TempFileName = "Copy of " & Doc.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & LCase(Right(Doc.Name, _
Len(Doc.Name) - InStrRev(Doc.Name, ".", , 1)))
'Op dit stuk loop ik vast!
' Create the attachment
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
ActiveDocument.Path & "\" & ActiveDocument.Name & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
Doc.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set Doc = ActiveDocument.Open(TempFilePath & TempFileName & FileExtStr)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With EmailItem
.Subject = "Verzoek om een bloemetje"
.Body = "Goedendag," & vbCrLf & _
"" & vbCrLf & _
"Hierbij het verzoek om een bloemetje te sturen." & vbCrLf & _
"" & vbCrLf & _
"Met vriendelijke groet," & vbCrLf & _
"Jan Jaap"
.BCC = ""
.To = "bloemist@bloemist.nl"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Send
End With
' Loop 1 sec om Outlook de kans te geven
' het e-mailbericht te versturen
s = Timer
Do While Timer < s + 1
DoEvents
Loop
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
MsgBox "Mail verzonden bedankt! ;-)"
End Sub]
Groeten,
Henning