Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/168561

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 10:03, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base

XL97: How to Programmatically Save a Worksheet as HTML

Article ID: 168561

Article Last Modified on 10/11/2006


  • Microsoft Excel 97 Standard Edition

This article was previously published under Q168561


An updated version of the Internet Assistant Wizard for Microsoft Excel 97 is available. This updated wizard allows you to export a worksheet to a Hypertext Markup Language (HTML) file by using a Visual Basic for Applications macro.

NOTE: The updated Internet Assistant Wizard is included with Microsoft Excel 97 for Windows, Service Release 1. If you have Microsoft Excel 97 for Windows, Service Release 1 installed, you do not need to download the file.

To obtain the updated Internet Assistant Wizard for Microsoft Excel, go to the following Web address:


Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example uses the HTMLconvert method of the Internet Assistant Wizard to create a Web page.

NOTE: In order to use this example, you must have the updated Internet Assistant Wizard add-in file (Html.xla), which is dated 4/29/97.

  1. Close and save any open workbooks, and then create a new workbook.
  2. Enter the following values on Sheet1:

    A1 : 2
    A2 : 4
    A3 : 6
    A4 : 8
    A5 : 10
    A6 :
    A7 : This
    A8 : is
    A9 : a
    A10: test

  3. Select cells A1:A5, and then click Chart on the Insert menu. In the "Chart Wizard - Step 1 of 4 - Chart Type" dialog box, click Finish.

    The result is a worksheet that contains two data ranges and one chart.
  4. Start the Visual Basic Editor (press ALT+F11).
  5. To use the Htmlconvert method of the Html.xla add-in, create a reference to this add-in. To create the reference, do the following:

    1. Click References on the Tools Menu.
    2. Click to select the HTML check box, and then click OK.

      Go to step 6.

      If you do not see the HTML, in the Available References list, click Browse.
    3. Open the folder that contains the updated Html.xla file. By default, the Html.xla file is installed in the following folder:

      C:\Program Files\Microsoft Office\Office\Library

    4. Click "Microsoft Excel Files (*.xls, *,xla)" in the Files Of Type list.
    5. Click Html.xla in the list of files, and then click Open.
  6. Click Module on the Insert menu to insert a Visual Basic module.
  7. Enter the following code into the module sheet:

       Sub CreateWebPage()
           Dim ObjToConvert(2) As Variant
           Dim Result As Integer
           ' Populate the ObjToConvert array with the ranges and chart
           ' that you want to export.
           Set ObjToConvert(0) = Sheets("sheet1").Range("a1:a5")
           Set ObjToConvert(1) = Sheets("sheet1").ChartObjects("Chart 1")
           Set ObjToConvert(2) = Sheets("sheet1").Range("a7:a10")
           ' Load the Internet Assistant Wizard add-in.
           AddIns("Internet Assistant Wizard").Installed = True
           ' Create the HTML page.
           Result = htmlconvert(rangeandcharttoconvert:=ObjToConvert, _
                                useexistingfile:=False, _
                                usefrontpageforexistingfile:=False, _
                                addtofrontpageweb:=False, codepage:=1252, _
                                htmlfilepath:="Test.htm", _
                                headerfullpage:="Test Page", _
                                linebeforetablefullpage:=True, _
           ' If the conversion is successful, the code htmlconvert_success
           ' is returned.
           If Result = htmlconvert_success Then
               MsgBox "Web Page Created Successfully"
               MsgBox "Error Creating Web Page"
           End If
        End Sub
  8. Run the CreateWebPage subroutine.

When you run the macro, a message box that indicates that the Web page was created successfully appears. You have two additional files in the current directory: Test.htm and Test0.gif. Test.htm is the HTML file, and Test0.gif is the chart that you converted.

If you run this subroutine several times, the Test.htm file is always overwritten, and a new .gif file is created each time. If, for example, you run the CreateWebPage subroutine six times, six .gif files are created. The Test.htm file points to Test5.gif, which is the latest .gif file.


For more information about the HTMLconvert method, refer to the section "HTMLconvert Function Documentation" in the Readme.txt file.

For additional information about how to add an add-in, click the article number below to view the article in the Microsoft Knowledge Base:

157768 XL97: Not all Menu Items Appear for Other Users

Additional query words: XL97

Keywords: kbdownload kbcode kbdtacode kbhowto kbofficeupdate kbprogramming KB168561