VBA - Macro to capture Table attributes from Word Document

3 views
Skip to first unread message

Neeraj Shinde

unread,
Jun 27, 2005, 5:11:37 AM6/27/05
to ProgrammingGuru
Following is the macro to put some HTML tags to tables in your word document.
This macro can be customised/improved with more attributes as per the
need and/or requirement.
 
Sub CaptureTableInformation()
    Dim aTable As Word.Table
    Dim aFile
    Dim aRow As Row
    Dim aCell As Cell
    Dim currText As String: currText = vbNullString
   
    aFile = FreeFile
    Open ActiveDocument.Path & "\" & Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 3) & "txt" For Output As #aFile
    For Each aTable In ActiveDocument.Tables
        Print #aFile, "<parag>"
        For Each aRow In aTable.Rows
            Print #aFile, "<tr>"
            For Each aCell In aRow.Cells
                ''Print #aFile, "<td align=""" & aCell.Range.ParagraphFormat.Alignment & """>"
                Print #aFile, "<td>"
                Print #aFile, "<parag>"
                currText = aCell.Range.Text
                currText = Replace(currText, "^p", vbNullString)
                Print #aFile, currText
                Print #aFile, "</parag>"
                Print #aFile, "</td>"
            Next aCell
            Print #aFile, "</tr>"
            Print #aFile, vbNullString
        Next aRow
        Print #aFile, "</parag>"
    Next aTable
   
    Close #aFile
End Sub
Reply all
Reply to author
Forward
0 new messages