Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel to html 1

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
I need to convert Excel file into HTML using VBA. I really appreciate any suggestions/ideas.

Thanks
 
an Excel VBA of my codes...
'**********************************************************
Sub htmlPublishObjects()
Dim wSheet As Worksheet, wBook As Workbook
MyPath = "C:\tEMP\d\*.xls" ' Set the path.
MyName = Dir(MyPath) ' Retrieve the first entry.
Do While MyName <> &quot;&quot; ' Start the loop.
Workbooks.Open Filename:=MyName, UpdateLinks:=3
Set wSheet = Application.ActiveSheet
Set wBook = Application.ActiveWorkbook
Call wSheet.Unprotect(&quot;myProtectionPssw&quot;)
ActiveWorkbook.PublishObjects.Add(xlSourceSheet, &quot;C:\tEMP\d\&quot; & _
Left(wBook.Name, Len(wBook.Name) - 3) & &quot;htm&quot;, _
&quot;MyTitle&quot;, &quot;&quot;, xlHtmlStatic, &quot;1wu&quot;, &quot;&quot;).Publish (True)
wBook.Close False
MyName = Dir ' Get next entry.
Loop
End Sub
 
Thanks for the response.

This logic works perfectly if we have only on sheet in excel workbook. I have multiple sheets in excel file. When we convert this excel file to HTML all the sheets should apprear in the same HTML file. I tried to loop through all the sheets and convert to HTML. The problem is it overwrites the same HTML file instead of adding tabs in same html file.

Any suggestions ?


Dim wSheet As Worksheet
Dim wBook As Workbook
MyName = &quot;C:\testing\Temp.xls&quot;

Workbooks.Open FileName:=MyName, UpdateLinks:=3

Set wBook = Application.ActiveWorkbook


For iLoop1 = 1 To wBook.Application.Sheets.Count
Set xlSheet = wBook.Application.Sheets(iLoop1)
Call xlSheet.Unprotect(&quot;myProtectionPssw&quot;)
ActiveWorkbook.PublishObjects.Add(xlSourceSheet, &quot;C:\testing\Temp.htm&quot;, xlSheet.Name, &quot;&quot;, xlHtmlStatic, &quot;1wu&quot;, &quot;&quot;).Publish (True)
Set xlSheet = Nothing
Next iLoop1

wBook.Close False
 
...
after unprotecting all sheets of the workbook,

ActiveWorkbook.SaveAs Filename:=&quot;D:\TEMP\myTmp33.htm&quot;, _
FileFormat:=xlHtml

ide
 
IT WORKED !

THANK YOU VERY MUCH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top