locked
How to convert selected table into html tags using word vba? RRS feed

  • Question

  • i want to know is there a option to convert the Activedocument.table(1).selection to html tags using word vba. If other options are there, please guide me. Thank you
    Wednesday, August 24, 2016 7:14 AM

All replies

  • One possibility is to save the selection as HTML e.g.

    Sub CopySelectedToHTM()
    Dim oSource As Document
    Dim oDoc As Document
    Dim oRng As Range
        Set oSource = ActiveDocument
        On Error Resume Next
        oSource.Save
        If Len(oSource.Path) = 0 Then
            MsgBox "Save the document first!"
            Exit Sub
        End If
        If Len(Selection) = 0 Then
            MsgBox "Select the text you wish to copy first!"
            Exit Sub
        End If
        Selection.Copy
        Set oDoc = Documents.Add(Template:=ActiveDocument.FullName)
        Set oRng = oDoc.Range
        oRng.Paste
        oDoc.SaveAs FileName:=Left(oSource.FullName, _
                                   InStrRev(oSource.FullName, Chr(46))) & "htm", _
                                   FileFormat:=wdFormatFilteredHTML
        oDoc.Close 0
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, August 24, 2016 8:44 AM
  • Thank you for your reply. but Without using save as option 
    Wednesday, August 24, 2016 8:50 AM
  • I wrote a simple converter years ago but it didn't do any styles.  I looked around for something that added styles and found this.  It looks well thought out.  You could remove the styles and add a separate stylesheet or you could use a CSS framework like Foundation or Bootstrap.

    • Edited by mogulman52 Wednesday, August 24, 2016 2:28 PM
    Wednesday, August 24, 2016 12:20 PM