Consulting

Results 1 to 4 of 4

Thread: Convert table to html tags without using saveas option in word vba

  1. #1

    Convert table to html tags without using saveas option in word vba

    Convert table to html tags without using saveas option in word vba

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,337
    Location
    What have you tried that does use saveas option in Word vba?
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Quote Originally Posted by gmaxey View Post
    What have you tried that does use saveas option in Word vba?
    tried to save the whole document (.docx) to (.html)...But i want to loop through each table in the active document and save it to html code in the word document itself.

  4. #4
    You posted a similar question at https://social.msdn.microsoft.com/Fo...a?forum=isvvba where I showed how to save a table to HTML format. If you want to save each table as HTML then that is a simple modification

    Sub CopyTablesToHTM()
    Dim oSource As Document
    Dim oDoc As Document
    Dim oTable As Table
    Dim i As Long
    Dim oRng As Range
    Dim strName As String
        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 oSource.Tables.Count = 0 Then
            MsgBox "There are no tables in the document"
            Exit Sub
        End If
        For i = 1 To oSource.Tables.Count
            Set oTable = oSource.Tables(i)
            oTable.Range.Copy
            Set oDoc = Documents.Add(Template:=oSource.FullName)
            Set oRng = oDoc.Range
            oRng.Paste
            strName = Left(oSource.Name, _
                           InStrRev(oSource.Name, Chr(46)) - 1) & "(" & i & ").htm"
            strName = oSource.Path & Chr(92) & strName
            oDoc.SaveAs FileName:=strName, _
                        FileFormat:=wdFormatFilteredHTML
            oDoc.Close 0
        Next i
    End Sub
    What is not so simple (or understood, as Word is not an HTML editor) is what you are trying to do with the html code relating to the table in the document?

    Please do not post to multiple forums without cross posting, to avoid a duplication of effort by those of us who provide our time to answer such questions.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •