''strWbk - Full path of the excel workbook
''strWsheetName - Name of the worksheet
'' strHTMLFile - Name of the html file with path
Public Function CreateHTMLFromExcel(strWbk,strWsheetName,strHTMLFile)
Set oExcel = Createobject("Excel.Application")
oExcel.visible = false
Set objExcelWB = oExcel.Workbooks.Open(strWbkPath)
Set objExcelWS = objExcelWB.Worksheets(strWsheetName)
'Getting the rows and column count
strColumnCount = objExcelWS.UsedRange.Columns.Count
strTotRows = objExcelWS.UsedRange.Rows.Count
strTable = "<table border=""""2"""">"
'Create html table based on content of the excel file
For j=1 to strTotRows
strTable = strTable & "<tr>"
For i=1 to strColumnCount
strData = Trim(objExcelWS.Cells(j,i))
strTable= strTable & "<td>"& strData &"</td>"
Next
strTable =strTable & "</tr>"
Next
strTable = strTable & "</table>"
set objFSO=Createobject("scripting.FileSystemObject")
set objtxt = objFSO.createTextFile(strHTMLFile)
objtxt.write(strTable)
'Closing the workbook
objExcelWB.Close
set objFSO =nothing
End Function
This approach can be helpful to convert XLS to html report in case of uft
ReplyDeleteJust want to say Thank You for the code snippet, works like a charm!
ReplyDelete