PDA

View Full Version : Is it possible to export to html without using save as?



ntupper
07-13-2010, 07:18 AM
Is it possible to export to html without using save as? I am trying to add in some dynamic reporting in the form of a pie chart to an active sheet that I use quite frequently. Rather than keep re-issuing the report I would like to export it to HTML so that it can be viewed at will. The only problem I have is that the only way I have managed to get it working is by using the Save As function - this causes issues because it obviously changes the excel sheet to an HTML file but it needs to refresh every minute or so. Is there another way? My current code is below;
Sub RefreshData()
ActiveWorkbook.Save
Call SaveIt
Call SaveToSharepoint
End Sub
Sub SaveIt()
ThisWorkbook.Save
Application.OnTime Now + TimeSerial(0, 1, 0), "SaveIt"
End Sub
Sub SaveToSharepoint()
'Autosaves to sharepoint for management reporting

ActiveWorkbook.SaveAs Filename:= _
"XXXXreport.htm" _
, FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False

mbarron
07-13-2010, 07:39 PM
Instead of saving the file as an html, you could copy the sheet(s) to a new file and then save that file as the html. Something like this:
Sub SaveAsHtml()
Dim wNew As Workbook, i As Integer
Dim wOld As Workbook
Application.ScreenUpdating = False
Kill "c:\test.htm"
Set wOld = ActiveWorkbook
wOld.Sheets(1).Copy
Set wNew = ActiveWorkbook

For i = 2 To wOld.Sheets.Count
wOld.Sheets(i).Copy after:=wNew.Sheets(Sheets.Count)
Next
wNew.Sheets(1).Activate
wNew.SaveAs "C:\test.htm", FileFormat:=xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
wNew.Close
Set wNew = Nothing
Set wOld = Nothing
Application.ScreenUpdating = False
End Sub

ntupper
07-14-2010, 04:23 AM
Thanks Mbarron - works perfectly.....