Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2007
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
ActiveSheet.Unprotect Password:=""
TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
Sub Mail_Sheet_Outlook_Body()
ActiveSheet.Unprotect Password:=""
Range("d15").Formula = "=Now()"
Range("d15").Value = Range("d15").Value
'log bijwerken
Sheets("Log").Select
ActiveSheet.Unprotect Password:=""
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Selection.Font.ColorIndex = 0
Selection.Interior.ColorIndex = xlNone
Selection.Font.Bold = False
Range("A2").FormulaR1C1 = "=Formulier!RC[2]"
Range("B2").FormulaR1C1 = "=Formulier!R[13]C[1]"
Range("C2").FormulaR1C1 = "=Formulier!R[13]C[1]"
Range("D2").FormulaR1C1 = "=Formulier!R[14]C[-1]"
Range("E2").FormulaR1C1 = "=Formulier!R[14]C[-1]"
Range("F2").FormulaR1C1 = "=Formulier!R[15]C[-3]"
Range("G2").FormulaR1C1 = "=Formulier!R[15]C[-3]"
Range("H2").FormulaR1C1 = "=Formulier!R[16]C[-5]"
Range("I2").FormulaR1C1 = "=Formulier!R[16]C[-5]"
Rows("2:2").Value = Rows("2:2").Value
ActiveSheet.Protect Password:=""
'nieuwe waarden copieren naar lijst
Range("D15:D18").Copy
Set PN = Worksheets("Lijst").Range("Volgnummer").Find(Range("c2").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not PN Is Nothing Then
Worksheets("Lijst").Unprotect Password:=""
Worksheets("Lijst").Range("M" & PN.row & ":P" & PN.row).PasteSpecial , Values:=True
Worksheets("Lijst").Protect Password:=""
End If
Application.CutCopyMode = False
Range("a1").Select
On Error Resume Next
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
With CreateObject("Outlook.Application").CreateItem(0)
.To = [lijst!c3]
.CC = ""
.BCC = ""
.Subject = "Reactie op " & [lijst!c6] & " volgnummer " & [lijst!c2]
.HTMLBody = RangetoHTML(Sheets("formulier").UsedRange)
.display
End With
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Range("D16:D18").ClearContents
Range("c2").Value = "Selecteer volgnummer uit lijst"
ActiveSheet.Protect Password:=""
End Sub