You are on page 1of 1

Public Function ExcelToHTMLFile(outputFileName as String,sheetName as String)As

String

On Error GoTo ErrHandler


Application.DisplayAlerts = False
Application.EnableEvents = False

Worksheets(SheetName).Activate

Dim iColumn As Long


Dim iRow As Long

iColumn = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column

iRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row

StartAddress = "A1"
EndAddress = Application.ConvertFormula(Range(Cells(iRow,
iColumn).Address).Address, xlA1, xlA1, 4)

dataRange = StartAddress & ":" & EndAddress

With ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceRange, _
FileName:=outputFileName, Sheet:=sheetName, Source:=dataRange, _
HtmlType:=xlHtmlStatic, DivID:="Book1_4170")
.Publish (True)
.AutoRepublish = False
End With

ExcelToHTMLFile = "HTML File Created Successfully"

Done:
Exit Function

ErrHandler:
ExcelToHTMLFile = "An Error occured while generating HTML file " &
vbNewLine & "Error Type: " & Err.Description
End Function

You might also like