Sub opslaan_en_mailen()
'If MsgBox("Loes weet je zeker dat de factuur goed is ?", vbQuestion + vbYesNo) = vbYes Then
'If lAnswer = vbYes Then Hoort bij MsgBox Loes....
'End If Hoort bij MsgBox Loes ....
'Author : Ken Puls ([url]www.excelguru.ca[/url])
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from [url]http://sourceforge.net/projects/pdfcreator/[/url])
' Designed for late bind, no references req'd
Dim pdfjob As Object
Dim sPDFName As String
Dim sPDFPath As String
MyName = Range("P29").Value & ""
'/// Change the output file name here! ///
sPDFName = MyName & ".xls"
'"testPDF.pdf"
sPDFPath = "E:\A2B4U\Opdrachten\2010\New\"
'ActiveWorkbook.Path & Application.PathSeparator
'Check if worksheet is empty and exit if so
If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing
If MsgBox("Factuur mailen ?", vbQuestion + vbYesNo) = vbYes Then
'versturen van pdf via mail
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
'.Subject = "Bijgaand de factuur, en bevestiging aflevering."
.Subject = "Betreft rit: " & Range("O33").Value 'Plaats - Plaats
.To = Range("O32").Value & "" 'vul hier een mail adres in
.CC = ""
.Bcc = ""
'.Body = Range("P31").Value & Range("O31").Value & vbNewLine & vbNewLine & Range("P32").Value & vbNewLine & Range("P33").Value & vbNewLine & vbNewLine & Range("P34").Value & vbNewLine & Range("P35").Value & vbNewLine & vbNewLine & Range("P36").Value & vbNewLine & Range("P37").Value & vbNewLine & Range("P38").Value & vbNewLine & vbNewLine & Range("P39").Value & vbNewLine & Range("P40").Value
.Body = Replace([P31] & [O31] & "#" & "#" & [P32] & "#" & [P33] & "#" & "#" & [P34] & "#" & [P35] & "#" & "#" & _
[P36] & "#" & [P37] & "#" & [P38] & "#" & "#" & [P39] & "#" & [P40], "#", vbNewLine)
.Attachments.Add sPDFPath & "\" & Replace(sPDFName, "xls", "pdf") 'Factuur word gemaild. (0123456789.pdf)
sPDFPath = "E:\A2B4U\Opdrachten\2010\"
.Attachments.Add sPDFPath & "\" & (Range("O29").Value) 'Vrachtbrief word gemaild. (0123456789v.pdf)
.Display
'.Save
'.Send
End With
Else
End If
'End If Hoort bij MsgBox Loes ....
'End Sub
'If Intersect(Target, Range("p11")) Is Nothing Then Exit Sub
Worksheets(6).Cells(11, 16) = 0
Application.Calculate
If Range("p11") = 0 Then
Rows("6:9").EntireRow.Hidden = True
ActiveSheet.PrintOut Copies:=1, ActivePrinter:="HP LaserJet 4100 PCL 6"
Else
Worksheets(6).Cells(11, 16) = 1
Application.Calculate
If Range("p11") = 1 Then
Rows("6:9").EntireRow.Hidden = False
End If
End If
End Sub