Rajneesh Rawat
New Member
- Joined
- Mar 31, 2017
- Messages
- 36
Hi Team,
I am stuck in one scenario where I want to left align the table in Mail. I did this kind of automation in past and this align perefectly but don’t know what I am doing wrong on below code or can anyone have any other solution.
I am stuck in one scenario where I want to left align the table in Mail. I did this kind of automation in past and this align perefectly but don’t know what I am doing wrong on below code or can anyone have any other solution.
Code:
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
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"
rng.Copy
Set TempWB = ThisWorkbook
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets("Format").Name, _
Source:=TempWB.Sheets("Format").UsedRange.Offset(1).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=")
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function