I working on a form that users will complete and depending on the selection in “Action Required” various lines in the form will change color from white to black using Conditional Formatting. I am doing this to try to make it simple for the users to complete only the lines that are required depending on the “Action Required” selection. When the form is complete, the user will push a button and run the code (from Ron de Bruin) shown below, it address, adds subject line, and adds the contents of the form into an email. The problem I am having is the line that change colors from white to black are not showing up in the email.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
The code below works well but I need it to copy to cells that are visible on the form to the email, can any one help me?
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
The code below works well but I need it to copy to cells that are visible on the form to the email, can any one help me?
Code:
[/FONT]
[FONT=Calibri]Sub Mail_Selection_Range_Outlook_Body()
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2010
ActiveSheet.Unprotect ' Unprotect, generate email.
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
<o:p> </o:p>
Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
Set rng = Sheets("Sheet1").Range("B3:AB20").SpecialCells(xlCellTypeVisible)
'You can also use a range if you want
'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
<o:p> </o:p>
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
<o:p> </o:p>
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
<o:p> </o:p>
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
<o:p> </o:p>
On Error Resume Next
With OutMail
.To = Sheets("Sheet1").Range("B1")
.CC = Sheets("Sheet1").Range("B2")
.BCC = ""
.Subject = Sheets("Sheet1").Range("B14")
.HTMLBody = RangetoHTML(rng)
.Display 'or use .Display or Send
End With
On Error GoTo 0
<o:p> </o:p>
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
<o:p> </o:p>
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Protect ' Reprotect the form.
End Sub
<o:p> </o:p>
<o:p> </o:p>
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
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
[FONT=Calibri]End Function[/FONT][/FONT]
[FONT=Calibri]