| Simple MakeHTML | Saving XML files |

A macro to make an HTML page from an Excel worksheet (advanced)

A visual basic macro

Excel contains a command to save an area of a worksheet in HTML format so that it can viewed through a web browser and incorporated in a website. The files created by this command are excessively large and contain limited formatting.

Alternatively a macro can be used to create a web page which contains better formatting and can be user defined to convert a particular range of a worksheet. If the page is to be regularly updated and published the macro can be linked to a button placed on your worksheet.

convert a worksheet to an html file using an Excel macro

A spreadsheet such as this can be converted into HTML code (a web page) and inherit the following features:

To view the converted page, click here. The HTML code includes some Cascading Style Sheet (CSS) instructions including a suitable format for displaying a table. For the purposes of a comparison, the equivalent (larger) file created using the Excel menu option 'SaveAsHTML' is also linked here.

A simpler version is available for data which is to be converted into a plain table. This will make a much more compact file.

The macro is intended to be incorporated within a spreadsheet which is occasionally converted and published. Rather than presenting the user with a series of dialog boxes in which they can enter the settings each time the macro is run, these settings can be declared as variables in the code of the macro itself. Therefore, although only a very limited knowledge is required, this solution is not appropriate to all users.

The macro is saved as a text file and can be opened here.
(version amended 2 May 05 - better FireFox compatibility)

Setting up the macro

Open your Excel spreadsheet that you wish to publish. Open the VBA editor and import a file containing 'MakeHTMLadvanced.bas' (or whetever name you used to save the macro text file). Alternatively copy and paste the code into a new module. The MakeHTM procedure should then be visible in a module.

Select and edit the procedure.

Would you like to learn more?

click link to find out about this book

Excel 2003 Power programming with VBA (with CD)

Return to your worksheet and run the MakeHTM macro.

Notes about the conversion

The output HTML file may not be a faithful reproduction of your original. Some of the defects can be resolved by amending your spreadsheet.

The macro was written by Chris Mead.

Get this information as a document
accompanied by Excel worksheets
The document is in PDF format Click here for details about
obtaining this file

W3Schools provides a collection of free HTML, CSS, JavaScript, DHTML, XML, XHTML, WAP, ASP, SQL tutorials with lots of working examples and source code. I have found this to be the most useful site for learning about anything web-related.

file: xladvhtml.htm © meadinkent.co.uk 2006 Last updated Oct06