| Feedback | Advanced HTML Macro | |
Excel contains an option to save a worksheet as an HTML file ([File] Save as | File type HTML). These generated pages are difficult to customise and can include unnecessary elements such as macro buttons and text boxes converted to images. The Microsoft style codes can contain non-standard instructions which are not understood by all browsers. If you have a minimal knowledge of HTML coding and can recognise the workings of a simple VB macro, the following code may offer a better solution.
- | A | B | C | D |
1 | Staff List | |||
2 | ||||
3 | Surname | Joining Date | Salary | Tax rate |
4 | Brown | 12/03/2001 | 12456 | 0.2 |
5 | Dunton | 12/01/1989 | 23456 | 0.25 |
6 | Elgar | 01/06/1995 | 32136 | 0.25 |
This Excel macro should be run from a worksheet containing a table you wish to save as a web page. There are various elements of code which need to be modified to reflect your individual table, such as the range of cells (FirstRow, LastCol etc) and a formatting style for each column for text, numbers or dates.
When run, the macro creates a text file containing all of the HTML code necessary for your page.
I have also produced a more complex alternative macro which generates a formatted web page from a worksheet.
Copy this code into a new macro module:
Option Base 1 ' sets first array element to 1, not 0
|
When the text file is opened using your web browser, the resulting page should look something like the following:
Staff List
You can search for a name or any detail using [ctrl]+'f'. Press [Home] to Source file: MakeHTML demo.xls | Page name: d:\tempm.htm | Created: 03 Nov 07 | MeadInKent.co.uk |
Note that to get an 'attractive' table, the HTML code should include some formatting instructions - either by defining some styles or by linking to an external Cascading Style Sheet . Neither of these options are essential however.
This macro makes a lot of sense when creating large tables because the generated code is less than the equivalent Excel menu option.
![]() |
Get this information as a document accompanied by Excel worksheets |
![]() |
Click here for details about
obtaining this file. It has been rewritten for Excel 2010. |
file: xlhtmltable.htm | © MeadInKent.co.uk 2016 | Last updated Feb14 | CMIDX S5 P2 |