Converting DataWindow to Excel file

// ... Init docname
// ... GetFileOpenName or any other method

if dw_1.SaveAs(docname, HTMLTable!, True) = -1 then
    MessageBox("Warning", "Unable to export data. Error writing to file!", Exclamation!)
    return
end if


// Convert HTML file to Excel native format
OLEObject excel
excel = CREATE OLEObject
if excel.ConnectToObject(docname) = 0 then
    excel.application.DisplayAlerts = FALSE
    excel.application.workbooks(1).Parent.Windows(excel.application.workbooks(1).Name).Visible = True
    excel.application.workbooks(1).saveas(docname, 39)
    excel.application.workbooks(1).close()
end if

DESTROY excel
// done