PDA

View Full Version : Convert table to html tags without using saveas option in word vba



Jeyaprabha
08-24-2016, 12:22 AM
Convert table to html tags without using saveas option in word vba:think:

gmaxey
08-25-2016, 05:56 AM
What have you tried that does use saveas option in Word vba?

Jeyaprabha
08-25-2016, 09:27 PM
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.

gmayor
08-26-2016, 01:33 AM
You posted a similar question at https://social.msdn.microsoft.com/Forums/en-US/be0d7c28-f762-4323-9582-1816938f38e7/how-to-convert-selected-table-into-html-tags-using-word-vba?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.