Supercharge your PowerPoint productivity with

Supercharge your PPT Productivity with PPTools - Click here to learn more.

Tell me about PPTools

Convert PowerPoint tables to HTML


PPTools
Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click
Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more
FixLinks prevents broken links when you distribute PowerPoint presentations
Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing
PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements
Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF
Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

Problem

You have a table in PowerPoint and want to use it as a stand-alone web page or to include it as a table in another web page you're building. Saving the slide as HTML results in very complex, uneditable HTML that you can't easily use in another program.

Solution

Select the PowerPoint table you want to convert to HTML then run the macro below.

Sub TableToHTML()    
    Dim oTable As Table
    Dim oSh As Shape
    Dim lColumn As Long
    Dim lRow As Long
    Dim sTableHTML As String

    ' No error checking here
    ' It's up to user to select a PowerPoint table before running this
    ' Note: POWERPOINT table, not pasted Word or Excel tables

    ' Start table off:
    sTableHTML = "<html>" & vbCrLf _
        & "<head>" & vbCrLf _
        & "</head>" & vbCrLf _
        & "<body>" & vbCrLf & vbCrLf _
        & "<table>" & vbCrLf

    Set oTable = ActiveWindow.Selection.ShapeRange(1).Table
    With oTable
        For lRow = 1 To .Rows.Count
            sTableHTML = sTableHTML & vbTab & "<tr>" & vbCrLf
            For lColumn = 1 To .Columns.Count
                sTableHTML = sTableHTML _
                    & vbTab & vbTab & "<td>" _
                    & .Cell(lRow, lColumn).Shape.TextFrame.TextRange.Text _
                    & "</td>" & vbCrLf
            Next
            sTableHTML = sTableHTML & vbTab & "</tr>" & vbCrLf
        Next
    End With

    ' finish up
    sTableHTML = sTableHTML & "</table>" & vbCrLf _
        & "</body>" & vbCrLf _
        & "</html>" & vbCrLf

    ' display the result in Immediate window
    ' Press Ctrl+G if you don't see the output
    Debug.Print sTableHTML

    ' Save to file
    Dim iFileNum As Integer
    iFileNum = FreeFile()
    Open "C:\Table.htm" For Output As #iFileNum
    Print #iFileNum, sTableHTML
    Close #iFileNum    
End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Page copy protected against web site content infringement by Copyscape Contents © 1995-2008 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese



Supercharge your PPT Productivity with PPTools


content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Convert PowerPoint tables to HTML
http://www.pptfaq.com/FAQ00748.htm
Last update 09 September, 2006